Hi All,
Is there anyway to bind the same Datasource(dataset) to 2 different UltraWinGrid on the same form.
DataSet has 4 tables, relation1 is between Table1 and Table2 and relation2 is between Table3 and table4.
I want to Bind the relation1 to UltraGrid1 and relation2 to UltraGrid2.
I already created the deign time bands for both the grid.
Any Suggestions/pointer please
With Thanks & Regards
Amjath
Hello,
Yes it is possible to bind UltraGrid to such way, so you should set as DataSource of the grid your dataset and also you should specify DataMember of the grid to the parent table of the relation which you want to display. Here is simple code snipped that creates dataset with 4 tables and two grids that display relations of the dataset:
DataSet ds = new DataSet();
DataTable t1 = ds.Tables.Add("table1");
t1.Columns.Add("id", typeof(int)).AutoIncrement = true;
t1.Columns.Add("Text", typeof(string)).Expression = "'table1 row'+[id]";
DataTable t2 = ds.Tables.Add("table2");
t2.Columns.Add("id", typeof(int)).AutoIncrement = true;
t2.Columns.Add("pid", typeof(int));
t2.Columns.Add("Text", typeof(string)).Expression = "'table2 row'+[id]";
DataTable t3 = ds.Tables.Add("table3");
t3.Columns.Add("id", typeof(int)).AutoIncrement = true;
t3.Columns.Add("Text", typeof(string)).Expression = "'table3 row'+[id]";
DataTable t4 = ds.Tables.Add("table4");
t4.Columns.Add("id", typeof(int)).AutoIncrement = true;
t4.Columns.Add("pid", typeof(int));
t4.Columns.Add("Text", typeof(string)).Expression = "'table4 row'+[id]";
for (int i = 0; i < 5; i++)
{
DataRow row1 = t1.Rows.Add();
DataRow row3 = t3.Rows.Add();
for (int j = 0; j < 5; j++)
t2.Rows.Add(null, row1["id"]);
t4.Rows.Add(null, row3["id"]);
}
ds.Relations.Add("t1 to t2", t1.Columns["id"], t2.Columns["pid"]);
ds.Relations.Add("t3 to t4", t3.Columns["id"], t4.Columns["pid"]);
ultraGrid1.DataSource = ds;
ultraGrid1.DataMember = "table1";
ultraGrid2.DataSource = ds;
ultraGrid2.DataMember = "table3";
Please let me know if you have any further questions.
Hi Hristo,
Thanks a lot.
Is it possible to assign the DataMember as Relationship name ?
because in one of my case, i have 3 tables in a dataset and need to assign it to 2 different ultrawingrid like as follows.
relation1 : table1 & table2
relation2 : table1 & table3
ultragrid1.datasource = relation1 &
ultragrid2.datasource = relation2
please let me know whether this is possible or not ??
In this case, the DataSource of both grids should by the DataSet and the DataMember of the child grid should be the name of the relationship.
This will work, so long as both grids are contained within the same control.
Hi Mike,
Im getting the following error, please suggest
child list for field relation2 cannot be created.
Sorry, The DataMember needs to include more than just the relationship name. You have to prepend the parent table name:
So it would be "Table1.Relation1"
Thanks a lot guys it worked.
-amjath