I'm converting a project from VB6 to VB.net. I use to use the 'UltraGrid' and ran into trouble where in VB.NET the cells in an axUltraGrid can't be edited. So I am attempting to replace with UltraWinGrid.
However I'm having issues binding my data to the grid. All data binding happens in code so to there are no form objects for datasources or any of that jazz.
==
dim adors as new adodb.recordset
adors.open "SELECT * FROM Accounts", CONN
ultragrid1.datasource = adors
===
What I get is a grid showing me the adodb properties. I tried messing with Infragistics.Win.UltraWinDataSource.UltraDataSource and System.Windows.Forms.BindingSource attaching them to the adors, without success.
Any suggestions / pointers?
Hi,
The DataBinding model in DotNet is different than in VB6. You need to bind the grid to a DataSource that implements the IBindingList or IList interface.
If you are getting your data from SQL, then the standard would be to use a DataSet or DataTable, which are the most common data source objects used in the DotNet Framework.
Thanks. I got it working, like you suggested I used System.Data.SqlClient.SqlDataAdapter
Now for multi-band 'Heirical' recordsets, I am using the System.Data.OleDb.OleDbConnection / System.Data.OleDb.OleDbDataAdapter.
A few initial problems. The band names went from the table name to 'table' + 'table' + 'table'.
so if I have a 3 dimensional shape (select * from tblMyTable1 .... relate tblMyTable2.... relate tblMyTable3.. my band name is nolonger
With .Bands.Item("table3") but is now
With .Bands.Item("tabletblMyTable1tblMyTable2tblMyTable3")
Very annoying.
And secondly it appears all band columns are the same width. If I resize the 2nd bands 2nd column it resizes all 2nd columns. Is there a property to 'break this up' that I am overlooking?
SirParadox said:A few initial problems. The band names went from the table name to 'table' + 'table' + 'table'.
The name of the band is determined by the name of the Relationship in the DataSet. So when you add the RelationShip to your DataSet, you can supply any Key you want. I think it uses the table names by default, but I'm pretty sure you can change it.
SirParadox said:And secondly it appears all band columns are the same width. If I resize the 2nd bands 2nd column it resizes all 2nd columns. Is there a property to 'break this up' that I am overlooking?
Yes, you need to set AllowColSizing (on the Override object) to any of the 'Free' settings.
== (Code Snippit)
dim sqlq as string = "SHAPE {SELECT * FROM tblEntities WHERE EntityID=3247} AS rsEntities APPEND ({SELECT * FROM tblMiscHosting} AS rsMiscHosting RELATE EntityID TO EntityID)"
Dim ds As New System.Data.DataSet()
Dim nwindConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=207.99.0.105;Integrated Security=SSPI;Initial Catalog=NACAS")
Dim adap As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(sqlq, nwindConn)
adap.Fill(ds)
UltraGrid1.DataSource = ds
I've tried leaving out the primary table 'rsEntities' name.. or leaving out both... No matter what I put in here the band(0).key = "Table"... then band(1).key = "TabletblEntitiestblMiscHosting"
Any suggestions? Am I using the wrong kind of system.data object?
I guess the Fill method must be automatically generating the name of the Relationship. So you may be stuck with it.
You cannot change the key on the grid band. You can try changing the relationship name on the DataSet.
ds.RelationShips(index or key).Key = newKey
But I probably wouldn't do that if I were you. It might cause you some trouble later on when you try to write the changes back to the database. The DataAdapter might get confused.
Why does it matter what the key is?
> I guess the Fill method must be automatically generating the name of the Relationship. So you may be stuck with it.
Do you have a better data fetch - populate code suggestion besides the fill?
I suppose that this thread is duplicate with case Ref. CAS-79891-TV28VK.
Maybe one possible approach to solve your task could be:Option 1:
namespace UltraGridDataBindingWithSQLDataAdapter { public partial class Form1 : Form { public Form1() { InitializeComponent(); string sqlq = "SHAPE { SELECT ID, sText FROM dbItems WHERE ID =10} APPEND ({SELECT ID, sDescription FROM dbRows } RELATE ID TO ID)"; DataSet ds = new DataSet(); System.Data.OleDb.OleDbConnection nwindConn = new System.Data.OleDb.OleDbConnection("Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=IGBGSOFDS22;Integrated Security=SSPI;Initial Catalog=Test"); System.Data.OleDb.OleDbDataAdapter adap = new System.Data.OleDb.OleDbDataAdapter(sqlq,nwindConn); adap.Fill(ds); ds.Tables[1].TableName = "BBB"; ds.Tables[0].TableName = "AAA"; ds.Relations[0].RelationName = "HHH"; ultraGrid1.DataSource = ds; } private void ultraButton1_Click(object sender, EventArgs e) { MessageBox.Show(ultraGrid1.DisplayLayout.Bands[0].Key + " --- " + ultraGrid1.DisplayLayout.Bands[1].Key); } } }
namespace UltraGridDataBindingWithSQLDataAdapter
{
public partial class Form1 : Form
public Form1()
InitializeComponent();
string sqlq = "SHAPE { SELECT ID, sText FROM dbItems WHERE ID =10} APPEND ({SELECT ID, sDescription FROM dbRows } RELATE ID TO ID)";
DataSet ds = new DataSet();
System.Data.OleDb.OleDbConnection nwindConn = new System.Data.OleDb.OleDbConnection("Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=IGBGSOFDS22;Integrated Security=SSPI;Initial Catalog=Test");
System.Data.OleDb.OleDbDataAdapter adap = new System.Data.OleDb.OleDbDataAdapter(sqlq,nwindConn);
adap.Fill(ds);
ds.Tables[1].TableName = "BBB";
ds.Tables[0].TableName = "AAA";
ds.Relations[0].RelationName = "HHH";
ultraGrid1.DataSource = ds;
}
private void ultraButton1_Click(object sender, EventArgs e)
MessageBox.Show(ultraGrid1.DisplayLayout.Bands[0].Key + " --- " + ultraGrid1.DisplayLayout.Bands[1].Key);
Please note that in this approach I set the name of the tables and releation outside of the SQL statement.Option 2:In this scenario I used a InnerJOin between both tables. [code]
namespace UltraGridWithTablesRelationsSQLSelect
private DataSet ds;
private DataTable dtParent;
private DataTable dtChild;
ds = new DataSet();
dtParent = new DataTable("Parent");
dtChild = new DataTable("Child");
dtParent.Columns.Add("ID",typeof(int));
dtParent.Columns.Add("sItem",typeof(string));
dtChild.Columns.Add("ID",typeof(int));
dtChild.Columns.Add("sDescription",typeof(string));
dtChild.Columns.Add("sNote",typeof(string));
ds.Tables.Add(dtParent);
ds.Tables.Add(dtChild);
DataRelation relation = new DataRelation("Relationship", dtParent.Columns["ID"], dtChild.Columns["ID"], true);
ds.Relations.Add(relation);
this.ultraGrid1.DataSource = this.ds.Tables["Parent"];
private void Form1_Load(object sender, EventArgs e)
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=IGBGSOFDS22;Initial Catalog=Test;Integrated Security=True";
SqlCommand cmd = new SqlCommand("select * from [dbItems] inner join [dbRows] ON [dbItems].ID =[dbRows].ID", conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
dtParent.Rows.Add(dr[0], dr[1]);
dtChild.Rows.Add(dr[2], dr[3], dr[4]);
[code]
Please try these approaches and I`ll wait your feedback. Please if you have any questions, do not hesitate to write me