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
close icon

Displaying Data from two DataTables

Hi, I have a DataSet with two DataTables with the same primary key. Its not a parent-child relationship. I have seperated the data in two tables for some reason. Now, I would like to diplay all the rows from both the tables in the DataGrid. What is the quickest way of achieving that? Thanks, Lalit

5 Replies

AD Administrator Syncfusion Team November 5, 2004 02:07 PM UTC

If these are just 2 flat tables you want to see in a grid, then using a virtual GridControl is one way to do it. In the QueryCellInfo handler, you would provide data from either table based on the e.RowIndex passed in, by setting the e.Style.CellValue appropriately. In QueryRowCount, you would return the total of the rows in both tables.


LP Lalit Parashar November 5, 2004 02:47 PM UTC

I have Table1 (10 columns, 1 Primary key), Table2 (10 columns, 1 Primary key). I would like to see 19 columns in the grid (since primary key is same in both the tables, i.e. ID). Thanks, Lalit


AD Administrator Syncfusion Team November 5, 2004 04:35 PM UTC

You could do this either with a virtual GridControl similar to what I suggested above, or you could it with a GridDataBoundGrid. With a GridDataBoundGrid, you could just assign the DataSource to be 1 table. Then you would add 9 unbound columns (sample of how to do this in grid\samples\databound\multiheader sample). In your QueryCellInfo event, you would get the primary key value, and use it and the COlindex (or column name) to find the proper value from the second table to set into e.Style.CellValue.


BM Brenda Maloff November 9, 2004 06:17 PM UTC

I also have to do something like this. I wanted to use a GridDataBoundGrid just for ease of use, but I noticed that it doesn''t have a QueryCellInfo event. Does that mean I have to use a true virtual grid? >You could do this either with a virtual GridControl similar to what I suggested above, or you could it with a GridDataBoundGrid. > >With a GridDataBoundGrid, you could just assign the DataSource to be 1 table. Then you would add 9 unbound columns (sample of how to do this in grid\samples\databound\multiheader sample). In your QueryCellInfo event, you would get the primary key value, and use it and the COlindex (or column name) to find the proper value from the second table to set into e.Style.CellValue. > >


AD Administrator Syncfusion Team November 9, 2004 06:59 PM UTC

In GridDataBoundGrid, you would use the grid.Model.QueryCellInfo event.

Loader.
Live Chat Icon For mobile
Up arrow icon