Hi...
Can u please help me in displaying parent and child rows in a single datagrid view in windows applications.
My requirement is a + sign should be there in the datagridview. on clicking that + sign child rows should get displayed for that parent row. How can i achieve that in windows forms. Please help me in this regard.
Expecting a earlier response as the requirement is urgent.
My another email address is [email protected]
Regards
Shwetha
Loading
shwethaPosted Jul 4, 2007, 1:16 PM
I tried this solution earlier, but it did not work.It is not showing any child records in the grid. I want this in datagridview control in VS 2005. Is this possible in .NET 2005?
Regards
Shwetha
Mahesh ChandPosted Jul 3, 2007, 1:22 PM
You select data from two tables in two DataTable objects and add both tables to a DataSet object and create a Parent-Child relation using DataRelation object. It a column name from Parent table, and a column name from Child table. After that, you add DataRelation to DataSet.Relations.
If you select data from two tables into a DataSet, do something like this:
// Create a DataRelation to link the two tables
// based on the SupplierID.
DataColumn parentColumn = dataSet.Tables["Suppliers"].Columns["SupplierID"];
DataColumn childColumn = dataSet.Tables["Products"].Columns["SupplierID"];
DataRelation relation = new System.Data.DataRelation("SuppliersProducts", parentColumn, childColumn);
dataSet.Relations.Add(relation);
Now if you bind this dataSet to a DataGrid, you will see PLUS sign and expanding it will show the relations and data related to that.
Chintan DesaiPosted Jul 3, 2007, 8:46 AM
Jan MontanoPosted Jul 2, 2007, 12:53 AM
http://www.codeproject.com/useritems/CoolGrid.asp
Cheers,
Jan