Hi Alfredo,
Thanks very much for your feedback.
Yes, for your requirement of displaying both the parent and child rows in
one table, there is no build-in support for the updating synchroniztion, we
have to do it in code manually.
Maybe we may refer to another design to workaround this issue:
I think your concern is displaying the all the child table's rows. We may
just select the parent and child tables in 2 datatables in one dataset, add
the datarelation. Then we may only display the child table in the main
DataGrid, then use the datarelation to display the selected child row's
parent row in another datagrid(or in several TextBox, as you like). Because
several child rows share the one parent row, this will be enough for the
customer to view them. Also, the only one parent row will eliminate the
parent row updating synchronization issue.
Also, we need to hook main DataGrid's currentcell change event to change
the parent datagrid's dispaly, keep the display synchronization. Also, we
may select all the child rows in the code to enable the user to view the
parent/child relation, sample code like this:
DataSet ds=null;
private void Form3_Load(object sender, System.EventArgs e)
{
SqlDataAdapter adapter=new SqlDataAdapter("select * from Orders",
"server=localhost;database=northwind;uid=sa;pwd=test");
ds=new DataSet();
adapter.Fill(ds, "Order");
adapter=new SqlDataAdapter("select * from [Order Details]",
"server=localhost;database=northwind;uid=sa;pwd=test");
adapter.Fill(ds, "Order Details");
ds.Relations.Add(new DataRelation("orderdetails",
ds.Tables["Order"].Columns["OrderID"], ds.Tables["Order
Details"].Columns["OrderID"]));
this.dataGrid1.DataSource=ds.Tables["Order Details"];
Bind_parentGrid();
}
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
Bind_parentGrid();
}
private void Bind_parentGrid()
{
CurrencyManager cm=this.BindingContext[ds.Tables["Order Details"]] as
CurrencyManager;
DataView dv=cm.List as DataView;
DataRow
dr=dv[this.dataGrid1.CurrentCell.RowNumber].Row.GetParentRow("orderdetails")
ds.Tables["Order"].DefaultView.RowFilter="OrderID="+dr["OrderID"].ToString()
;
this.dataGrid2.DataSource=ds.Tables["Order"].DefaultView;
if(dr!=null)
{
DataRow[] child_rows=dr.GetChildRows("orderdetails");
for(int i=0;i<dv.Count;i++)
{
foreach(DataRow row in child_rows)
{
if(dv
.Row.Equals(row))
{
this.dataGrid1.Select(i);
}
}
}
}
}
It works well on my side.
Anyway, this is only a design option for your information.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.