Chlid rows of a datarow

G

Guest

Hi

I have a sortable readonly datagrid bound to a strongly typed dataset parent
table which has an associated child table via a relationship. I can get the
selected datatable row via the BindingManagerBase. I then want to launch a
new windows form and display the columns of the selected row for editing. I
do this by adding a form property to the new form in order to accept the
selected datarow. This is then used to bind to each of the controls for
editing which works fine.

The question is, given that I have the required datarow in the new form, how
do I bind the results of the row.GetChildRows to another datagrid?

Any help would be much appreciated.
 
K

Kevin Yu [MSFT]

Hi Terry,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to get the
childrows from the parent row and bind the results to a DataGrid. If there
is any misunderstanding, please feel free to let me know.

Just as you know, we use GetChildRows method to get the child rows of a
certain DataRows. The method returns an array of DataRows which can be used
as the DataSource of a DataGrid directly. Here is an example of the
Customers and Orders table. HTH.

private void Form1_Load(object sender, System.EventArgs e)
{
this.sqlDataAdapter1.Fill(this.dataSet11.Customers);
this.sqlDataAdapter2.Fill(this.dataSet11.Orders);
this.dataGrid1.DataSource = this.dataSet11.Customers;
this.cm = (CurrencyManager)this.BindingContext[this.dataSet11.Customers];
this.cm.PositionChanged +=new EventHandler(cm_PositionChanged);
}

private void cm_PositionChanged(object sender, EventArgs e)
{
this.dataGrid2.DataSource =
this.dataSet11.Customers.Rows[this.cm.Position].GetChildRows("CustomersOrder
s");
}

For more information about GetChildRows, please check the following link:

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

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

Guest

Thanks Kevin

I have done as you suggest and the basic functionality works except the
child datagrid now displays all of the child table columns plus others like
'HasErrors', 'RowError' etc.

The parent datarow is strongly typed - not sure if this has any impact?
 
K

Kevin Yu [MSFT]

Hi Terry,

The HasErrors and RowError columns appear, because we are binding to the
DataRow array as DataSource, instead of using the DataTable. To show a
normal DataGrid, we have to copy the DataRows returned from GetChildRows
method and add them to a new DataTable one by one. Then bind the DataGrid
to DataTable. This is a little complicated, but I could not see a better
way since you're passing the master and detailed table between forms.

The best practice within a form is to use the method the following article
provides.

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

In the next version of .NET framework, we are provided with more
functionalities on manipulating Master-Detail tables.

HTH.

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