Hi,
I have an UltraWinGrid on a windows form, to which I bind a dataset to display a data.
When I click on any one of the rows by clicking the '+' symbol, I must display an indented set of at least one or more rows as a child row.
Here's my approach:
(a) Get a new dataset containing only those child rows.
(b) Create a parent child relationship constraint with the existing main dataset and bind it to the grid.
If the above approach is not the best, Please specify what can be the best approach to do this.
Thanks in advance,
Scott.
Hello,
I bind the grid to a dataset which only has one table with no child tables. Now inside the mygrid_BeforeRowExpanded event, I create a new dataset which has the same data as the current dataset plus child relation constraint by using DataRelation. Now the dataset has two tables. One is parent and the other is child with a unique key.
I now call mygrid.DataSource = newdataset;
When I execute it and try clicking the '+' sign this does not show any child rows. It only shows the basic grid with parent rows.
Am I missing any thing. Please help.
Thanks,
Adding to the above, If I place the code in a Button click event, it properly displays the parent child as a related view on the Grid. However, if i do this on a BeforeRowExpanded event, it does not.
Mike,
As per your suggestion, I am following the approach of creating parent/child datarelation
upfront with empty children and then binding it to the grid.
The grid does not display the children when I proceed with the above approach.
When it gets binded the first time, it has the parent child relationship with children
table being empty. However, when I click a row, inside "BeforeRowExpanded" event,
the dataset gets changed altogether
with the children now having some rows. Binding this does not cause the grid to
display any children.
Is there a specific method or property that you specify? In other words, is there something that causes the grid to reset its contents inside the row event ? All i do is set the datasource property of the wingrid to the new dataset which HAS parent child datatables in it.
There is no way this will work by setting the grid's DataSource. Setting the DataSource will cause the grid to destroy all rows and columns and rebuild itself based on the new data source. So it will not be able to maintain the states of the expanded row.
My sugesstion is to create the data structure with a 2-level hierarchy up-front. Then you can load the data inot your data source as you need it when rows are expanded.
But the DataBinding in DotNet is really not set up to load on-demand, and I suspect there may be other issues getting this to work, which is why you might also want to use the UltraDataSource.
Either way, though, you are really kind've fighting against the way the DotNet Framework is designed.
Hi Mike
This is what I am doing as per what you mentioned.
(a)Create a dataset that has parent rows. Add a datatable which has no rows and shows an empty child table to this dataset.
(b)Set up relationships and bind it to the grid. The grid now only shows parent rows.
(c)When a row is clicked, inside BeforeRowExpanded event, CREATE A NEW DATASET that gets two different datatables, merges them, sets datarelation and i assign that to the grid's datasource.
(d)I still do not see any child rows.
Notice that I am CREATING another dataset but has same child/parent structure as the one that i binded to the grid initially. Am i supposed to use the SAME dataset that was used to bind the grid initially? If yes in what way. Do i need to keep a form variable dataset type and assign it. Please specify.
iamscotthetfield said:(c)When a row is clicked, inside BeforeRowExpanded event, CREATE A NEW DATASET that gets two different datatables, merges them, sets datarelation and i assign that to the grid's datasource.
If you are changing the DataSource on the grid and the grid is not displaying the data in that data source, then I'm afraid I have no explanation for that. Are you certain that the data source actually contains the child rows? Does it work if you simply bind the grid to this hierarchical data source initially, without doing it inside the grid events?
In any case, what you are doing here is not going to work. Even if the grid updated, setting the grid's DataSource property is an extremely destructive process. All rows, columns, bands, and the grid layout will be destroyed and an entirely new set of them will be created in order to display the new data source. You will lose all state information, any pending changes, layout information, etc. It does not matter if the structure is the same. The user would be unable to expand the row because the row would be destroyed every time they clicked on the expansion indicator.
You should not have to set the grid's DataSource, though. If you simply add the necessary child rows to the existing child table in the DataSet, then that should be sufficient and a whole lot less destructive, not to mention far more efficient.
Is there anyway to display a BOM a parent having children and tghe children potentially having more children within a grid
Hi Scott,
i am writting a similar solution to this and it happens to work too but i have the same problem with duplicate rows. Have you reached to a solution for this issue?
thanks,
i am trying the same thing. Could you give us more details about the correct solution?
Marova
The child list now appears in the grid. All I did is
(a)Get the current dataset (having parent/child relation) .
(b)Add child rows to the child datatable inside it.
(c)use the statement setDataBindings(datasource,""); inside BeforeRowExpanded event.
It now shows the rows. The only issue now would be to make sure it won't add duplicate rows
again and again whenever the BeforeRowExpanded event happens.
Thanks a lot for your help Mike.
For you initial question, Yes the grid does have its datasource containing a second child table. However, it does not expand the children as there are zero rows in that table. Hope it helps.