Filtered view on second DataGridView

G

Guest

I have an XML data file with several nested tables two to three layers deep.

I want to use two DataGridViews to show and edit the data then save the data
back to the XML file.

I want the top DataGridView to show the parent data. If clicking any row of
the parent I then want to display in the second DataGridView the nested child
table entries of the parent.

I've looked at BindingSource and filters but I don't understand how to
establish the proper relation in the second DataGridView so that the correct
child tables will correctly display.

Can someone point me in the correct direction on how this is done? Your
help would be very much appreciated!
 
K

Kevin Yu [MSFT]

Hi Steve,

To achieve this, you can try to use the typed DataSet. If the xml data
files are in DataSet format, you can load them into DataSets using
DataSet.ReadXml method. You can also create a DataRelation between the two
related tables.

After a user selects a row in the parent table, you can use
BindingSource.Current to find the current row in the DataSet. Call
DataRow.GetChildRows to get the child rows.

You can also achieve this by using data binding for both parent and child
tables. Please check the following link for an example:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskcreatingmasterdetailslistwithdatagrid.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Kevin,

With the direction you provided I was able to come up with the solution that
was quite simple. My code is simply:

private void dataGridViewConceptsA_RowEnter(object sender,
dataGridViewCellEventArgs e)
{
DataRowView dataRowView =
(DataRowView)(((DataGridView)sender).Rows[e.RowIndex]).DataBoundItem;
this.bindingSourceExample.DataSource =
dataRowView.CreateChildView("Concept_Example");
}

This did the trick. Thanks.
 
K

Kevin Yu [MSFT]

Hi Steve,

It was nice to hear that you have had the problem resolved. Thanks for
sharing your experience with all the people here. If you have any
questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top