What is wrong with my code?
If I just bind the GetTable dataset gives me the right data. But If I add the relation with this empty table, gives me any empty table with only one column ("Column 0"). It should display my primary table with an option to expand (+).
Dim ds As DataSet = GetTable() If ds IsNot Nothing Then Dim dt As New DataTable("Temp") dt.Columns.Add("ID") ds.Tables.Add(dt) ds.Relations.Add(ds.Tables(0).Columns(0), ds.Tables("Temp").Columns(0)) End If Me.UltraGrid1.DataSource = ds
My problem though is this:
With the temporary table above, I can make the expandindicator appear since it can now see the relations.
My code under BeforeRowExpanded event is this:
Dim dt As DataTable = CType(UltraGrid1.DataSource, DataSet).Tables(1)
Dim dt2 as Datatable = GetTable2()
dt = dt2.Clone()
For Each r As DataRow In dt2.Rows dt.ImportRow(r)Next
-- With this code, 'dt' table is indeed populated with the data but not reflected in the grid.
I checked CType(UltraGrid1.DataSource, DataSet).Tables(1) - row count is still 0 but dt has some rows.
The problem actually with my code is I did not set the datatype of the new column which should match with the column in the first table.
Try setting the DataMember property to the name of Tables(0). Incidentally, you can set the DataSource and DataMember in one atomic operation using the SetDataBinding method.