Hi,
There are 3 tables in the DB: AàBàC
(A is the father, B is the son, C is the grandson).
I have 2 grids: grdA and grdC.
grdA has 2 Bands: band0 displays the data of tableA, band1 displays the data of table B.
grdC displays the data if table C.
I want that when I select a row in grdA-band1, the data in grdC will be updated accordingly.
Problem is that the data in grdC is updated according to the selected row in grdA-band0.
The grids are bounded to the tables in that way:
bsA – hold the data of table A.
grdA.DataSource = bsA;
bsB.DataSource = bsA;
bsB.DataMember = "B";
bsC.DataSource = bsB;
bsC.DataMember = "C";
grdC.DataSource = bsC;
Thanks ahead,
Yael
I'm adding a new row differently now:
UltraGridBand
bandC = grdA.DisplayLayout.Bands["C"];UltraGridRow newRow = bandC.AddNew();
Then I added:
grdC.Rows.Refresh(
RefreshRow.ReloadData, false);
Now the display of the grid is updated immediately :)
Thanks a lot!Yael
Hi Yael,
If the row is not appearing in the grid, it means that the DataSource is not sending a notification to the grid that a new row was added.
I my example, where I am using a DataSet, there's no way to add a row directly to another row with the syntax you are using here. So my guess is that your data source contains custom objects and you are not properly implementing IBindingList to send the add notification when you call the Add method on your C property.
So the best thing for you to do is implement IBindingList.
Alternatively, you can tell the grid to update it's display any time you change something in code. To do this, you use the Refresh method on the rows collection.
this.ultraGrid2.Rows.Refresh(RefreshRow.ReloadData, false);
Thanks a lot for your detailed answer!!!
It is working now :)
I have another question on the same issue:
When adding new row to grdC (or UltraGrid2 in your example),I don't see immediately the new row, but only after I go to another row in grdA, and then get back and I see the new row.
The way I added the row:B objB = (B)grdA.ActiveRow.ListObject; //the current B rowobjB.C.Add(newObj);
The workaround:I add new row through the binding source and then delete it.
Is there a way to see immediately the newly added row?
Thanks a lot,Yael
I tried this out and it's a bit trickier than I expected. Apparently, in order to get the second grid bound to the grandchild relationship, you have to specific the entire binding hierarchy.
So if your three tables are A, B, and C. And the relations between those tables are AB and BC, then you have to bind the second grid to "A.AB.BC".
I have attached a working sample here so you can check it out.
Grids A and C are inside the same container.
I also added ("this" represents the form):
grdA.BindingContext =
this.BindingContext;
grdC.BindingContext =
Still, it doesn't help :(When activating a different child row (band1 - that belong to table B) in grdA, it has no effect on grdC,unless it belongs to a different row (-in band0. So the rows in grdC still changing according to the relevant row in band 0).
Any idea?
Thanks!Yael