Let me first explain what I try to achieve before I go into details about my problems.
I have to datatables A and B that have a many-to-many relationship. That is to say that a row in A can have many childrows in B. And that a row in B can belong to many rows in A.
To do this I had to introduce a new table, R, that contains the links between A and B.
When I add this datasource I get three bands corresponding to the tables.
A
- R
- B
This is not what I want. I would rather just show the bands from A and B. That is to show all the B childrows to a given A row.
Is there any way to do this?
One solution to get it to display properly is to join the R and B tables.
This works for display purposes, but is not that good when you try to update B, since you will have multiple duplicates of B in the new table.
I found the answer to make sure the grid is updated:
ultraDataSource1.ResetCachedValues();ultraGrid1.Invalidate();
I have tried to implement this many-to-many relationship with virtual mode on an UltraDataSource.
I have a small problem though.
If a row in the datasource B is visible in two different subbands A1 and A2 and I update the value in one of them, the other one is not updated untill I hover the mouse over it or else manipulates it. Is there any way to tell the UltraGrid to reload the data of all of the visible bands?
If you hide band R, then you cannot show it's child bands.
What you would have to do in this case is bind the grid to a data source that does not include the R band and has a direct relation between A and B.
One way you might go about this without changing your real data source is to use the UltraDataSource component in On-Demand mode. Check out the Virtual Mode sample for an example of this technique. Basically, the UltraDataSource would have two bands: A and B. And you would handle the events of the UltraDataSource like CellDataRequested to fill in the data. Then your code could examine a row in Band A, get the child rows for Band B and return them as though they were direct children of A rather than Grandchildren via band R.