We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Binding to the childrows of a parent datarow

Is it possible to bind a databound grid to the child rows of a parent row by supplying a datatable relation object to the data bound grid? I have an order, which has order sub-sections which are laid out on seperate tab pages. Each tab page has a grid which displays the order sub-section order-items. At the moment I am using dataviews, and dynamically changing the rowfilter as each tab is clicked, so that the correct order items are displayed. I am also changing the default values for the datacolumns so that new order items are added in the correct place i.e. with the correct foreign keys. This is cumbersome. I seem to remeber that using .NET grids you could supply a parent row, and then bind the grid to its children by supply a datatable relation object. Is there an eqivelent in essential grid? Thanks, Tim.

17 Replies

AD Administrator Syncfusion Team October 6, 2003 10:14 PM UTC

I don't think there is a simple solution right now. The closest you can get is with the hierchical grid (see the DataBound\Hierarchy\ExpandGrid example). With the next version 2.0 we will have support for grouping and also nested/related tables. With that version you will be able to initialize the grid with a dataview that consist of child tables and display them below each other and expand/collapse them. Stefan


TL Tim Lloyd October 7, 2003 01:30 PM UTC

Thanks Stefan, but this is not really what I'm looking for. I originally started writting my application using .NET grids, and eventually gave up and bought Essential Suite - horray! The API is so much more complete and intuitive. I digress.. When I used .NET grids, I used a dataview manager and datarelation objects so that I could display grids which were 'navigated' to the child rows of parent rows. This worked well as any rows that were added to the grids were added with the correct foreign keys and parent row relation. Using this mechanism I could display a tab page layout which had grids for each parent row (displaying related child rows), and the user could tab through grids and add rows. These rows would be added to the appropriate parents. I am looking for the same functionality - not a nested table display. Maybe I'll try creating seperate datatable's dynamically with cloning, and then do a merge at save time. The method I'm using at the moment with dataviews, rowfilters, and default column values is working, but it's not very elegant. Is there a way to intercept rows that are being added so that I could put a seg in that assigned the new child row's parent row. This would be much more elegant and be more intuitive to any maintenance coders. Many thanks, Tim.


AD Administrator Syncfusion Team October 7, 2003 03:08 PM UTC

Do you have a sample project how you did this with the .NET DataGrid? Then I could try and replace the DataGrid with GridDataBoundGrid. Maybe its just that I didn't fully understand the problem. With GridDataBoundGrid there are no rows actually added to the grid. It just gets the rowcount from the listmanager/underlying dataview in QueryRowCount and then access these rows directly in the listmanger (in QueryCellInfo) when displaying them. Stefan


TL Tim Lloyd October 7, 2003 06:23 PM UTC

Stefan, Many thanks for the feedback. I have gone through my backups, and the original code has been consigned to the bit-bucket as I have been using the essential grid with considerable vigour and disregarded my code based on the .NET grid stuff - hehe. I have made a mockup of what I was originally doing and have attached a codefile as well as a screen shot of the tab-style interface I am now working with. Essentially I was using SetDataBinding to set a grid's datasource to a dataSet and a specific table, and then using NavigatTo to navigate the grid to the childrecords before displaying it. By iterating through a parent table's datarow's, a seperate grid containing child records for each parent row can be made. Phew. The handy thing about doing this, is that adding rows to each grid will be done using the specified datarelation in NavigateTo code. When changes are saved, and the updated keys retrieved from the database, all keys are propagated, etc. Getting the same effect with essential grid would be ideal. Take a look at the attached code. I have been hammering the coffee today, so hopefully this makes sense... Many Thanks, Tim.


TL Tim Lloyd October 7, 2003 06:31 PM UTC

Stefan, PS. I see your point about the way the databound grid is related to the underlying datasource. When a row is added to the grid by the user and it is then commited when the user moves off the row, would there be any way of setting the added datrow's parent datarow? Many thanks, Tim.


TL Tim Lloyd October 7, 2003 07:09 PM UTC

Forgot to add code for maintaing seperate binding contexts for each grid. New codefile attached. Tim.


AD Administrator Syncfusion Team October 7, 2003 07:17 PM UTC

Thanks, but can you make this a complete project that works with the Northwind database? I especially also wanted to see how the datasource was setup... Sorry for being so picky here but creating samples on my own is always harder than it seems if you don't know all the details. Stefan


TL Tim Lloyd October 7, 2003 09:47 PM UTC

Stefan, Please find attached a sample which uses the northwind.mdb database which it expects to find in C:\ unless you change it. The example shows all orders and their order items for a selected customer. This is presented in a dynamic tab-style interface where each order can be edited (only inserts in this example). The application is very slow as it loads three tables in their entirety, so you'll have to bear with it. The example does try to demonstrate what I've been trying to describe. Hope this does the trick. Thanks, Tim.


AD Administrator Syncfusion Team October 8, 2003 11:44 AM UTC

I got the sample and see now what you need. I'll get back to you if I find something out. But give me a couple days. Thanks, Stefan


AD Administrator Syncfusion Team October 10, 2003 04:41 PM UTC

Attached find a modified sample. The key is the DataView.CreateChildView method: CurrencyManager cm = (CurrencyManager) BindingContext[_ds, dtCustomers.TableName]; DataView dv = cm.List as DataView; for (int i = 0; i < customerOrderCount; i++) { ... DataView filtered = dv[i].CreateChildView("CustomerOrder"); CurrencyManager cm2 = (CurrencyManager) BindingContext[filtered]; DataView dv2 = cm2.List as DataView; DataView filtered2 = dv2[i].CreateChildView("OrderOrderItem"); databoundgrid.Binder.SetDataBinding(filtered2, null); } Stefan


TL Tim Lloyd October 13, 2003 02:34 PM UTC

Stefan, Many thanks for the new sample code - exactly what I was looking for. I hadn't come across 'CreateChildView' before. This should enable me to clean up some other areas of code where it would be useful. I have pared down the code that I originally produced plus the new code, but have come across a problem. If each grid is not added to a parent panel control before being added to the tab control, you cannot close the form. I have included a new project where adding the grids to panels is controlled through the '_usePanelForGrid' variable in the form constructor. Do you have any idea what is causing this behaviour. Many thanks, Tim.


AD Administrator Syncfusion Team October 13, 2003 06:09 PM UTC

That's really weird and I have not really an idea. Usually you cannnot close the form when somebody is handling either the OnClosing event or OnValidating event and that sets e.Cancel = true; I added a databoundgrid.CausesValidation = false; to make sure the grids OnValidating is not called but that did not make a difference. What you could check next is if OnClosing is raised or OnValidating for any of the tab pages or the tab control or the grids. Stefan


TL Tim Lloyd October 13, 2003 08:04 PM UTC

Stefan, I have attached an OnValidate event handler to the tabpages and grids, and it is not being raised when the grids are added directly to the tabpages. Should I raise a tracker and submit the example code? Tim.


AD Administrator Syncfusion Team October 13, 2003 09:32 PM UTC

Compile your project with VS.NET 2003 / .NET Framework 1.1. Then it is fine. This is most likely a bug in the 1.0 framework. Stefan


TL Tim Lloyd October 13, 2003 09:47 PM UTC

Stefan, Unfortunately I am working with VS2002 and .NET 1.0 (with patches...). I'll work around it. Thanks, Tim.


AD Administrator Syncfusion Team March 5, 2004 06:22 PM UTC

> > Do you have a sample project how you did this with the .NET DataGrid? Then I could try and replace the DataGrid with GridDataBoundGrid. Maybe its just that I didn't fully understand the problem. > > With GridDataBoundGrid there are no rows actually added to the grid. It just gets the rowcount from the listmanager/underlying dataview in QueryRowCount and then access these rows directly in the listmanger (in QueryCellInfo) when displaying them. > > Stefan >>>> Is there any way to replace DataGrid with GridDataBoundGrid ?? Thanks. >>>> mark


AD Administrator Syncfusion Team March 5, 2004 06:23 PM UTC

> > Do you have a sample project how you did this with the .NET DataGrid? Then I could try and replace the DataGrid with GridDataBoundGrid. Maybe its just that I didn't fully understand the problem. > > With GridDataBoundGrid there are no rows actually added to the grid. It just gets the rowcount from the listmanager/underlying dataview in QueryRowCount and then access these rows directly in the listmanger (in QueryCellInfo) when displaying them. > > Stefan >>>> Is there any way to replace DataGrid with GridDataBoundGrid ?? Thanks. >>>> mark

Loader.
Up arrow icon