View previous topic :: View next topic |
Author |
Message |
jaherbert
Joined: 27 Jan 2008 Posts: 43
|
Posted: Fri Feb 18, 2011 11:19 pm Post subject: Multiple ChildRelations, Same Table |
|
|
I have a recursive (DataSet) relationship that creates a hierarchy of categories. The leaves of these categories have detail items. So, there's a recursive relationship among the rows of table1 and the leaf nodes of table1 have a master/detail relationship with table2.
Is it possible to display in a single tree with table1 having two different kinds of children?
Thanks. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Feb 19, 2011 12:30 am Post subject: |
|
|
Yes this would be possible - however you would need to handle the GetChildren event programmatically (ie you can't just use design time binding to handle this).
Binding to datasets is a little trickier than to other objects because of the way they use DataRowViews. Here is the basic code you would need in the GetChildren event handler just to replace the standard functionality (minus sorting):
Code: | private void _virtualTree_GetChildren(object sender, GetChildrenEventArgs e)
{
DataRow dr = e.Row.Item as DataRow;
if (dr != null)
{
DataRelationCollection relations = dr.Table.ChildRelations;
if (relations.Count > 0)
{
DataRowView drv = DataRowRowBinding.GetDataRowView(dr);
if (drv != null)
{
// need to determine the correct relation to use here
//
DataView childView = drv.CreateChildView(relations[0]);
e.Children = new DataViewList(childView);
}
}
}
else // for the table just call the default binding method
{
RowBinding binding = _virtualTree.GetBindingForRow(e.Row);
e.Children = binding.GetChildrenForRow(e.Row);
}
} |
The DataViewList class is a wrapper class (in the VirtualTree namespace) that returns the underlying DataRows from a DataView.
Your code would need to select the child relation you wanted to use. _________________ Infralution Support |
|
Back to top |
|
|
jaherbert
Joined: 27 Jan 2008 Posts: 43
|
Posted: Tue Feb 22, 2011 10:15 pm Post subject: |
|
|
Thanks. |
|
Back to top |
|
|
|