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.
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.
In the beginning when I bind the parent rows, the child datatable does not has any rows (but it has a datarelation). Hence the children can't be seen upfront i.e. during initial grid bind. However, when i debug the code and do a quick watch on the Grid.Datasource, there are 2 tables with rows shown.
Now inside the BeforeRowExpanded event, you mentioned to CHANGE the existing dataset by adding child datatable and then bind it. Technically, HOW DO I APPLY this new dataset to the grid. in other words what statement does the job of updating the grid. If I choose the .Datasource property then it destroys everything then how do i set this modified dataset to the grid. How does the grid know that the dataset is modified now and It needs to reload new items. Please specify.
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.
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.
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