Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Several DataRow Types per Level

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
flc.net



Joined: 21 Jun 2005
Posts: 89
Location: Switzerland

PostPosted: Tue Feb 07, 2006 12:48 pm    Post subject: Several DataRow Types per Level Reply with quote

Hello Support

Please have a look at our Sample DataSet.

(big image)

It's possible that the result looks like this (each Row has his own type)?


(big image)

Thanks and Best Regards
Giuseppe
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Feb 07, 2006 10:56 pm    Post subject: Reply with quote

It is possible to do this sort of thing by handling the GetChildren event programmatically. For example:

Code:
private void _virtualTree_GetChildren(object sender, GetChildrenEventArgs e)
{
    RowBinding binding = _virtualTree.GetRowBinding(e.Row);
    if (binding == this.rowBindingCustomers)
    {
        DataRowView drv = e.Row.Item as DataRowView;
        DataView dv1 = drv.CreateChildView("CustomersOrders");
        DataView dv2 = drv.CreateChildView("CustomersInquiries");
        DataRowView[] children = new DataRowView[dv1.Count + dv2.Count];
        dv1.CopyTo(children, 0);
        dv2.CopyTo(children, dv1.Count);
        e.Children = children;
    }
    else
    {
        e.Children = binding.GetChildrenForRow(e.Row);
    }           
}


Note that if you want to support sorting then you will also need to check the current SortColumn and set the sort on the child views accordingly.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
dinabandhu



Joined: 19 Sep 2007
Posts: 9

PostPosted: Wed Sep 19, 2007 1:15 pm    Post subject: The display is not correct Reply with quote

Hi,

I tried this approach but the tree shows the text "System.Data.DataRowView" in the child rows instead of showing the data using rowbindings created on the design mode.

Can you please help.

Regards,

Dinabandhu
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Sep 19, 2007 9:53 pm    Post subject: Reply with quote

The code was for an earlier version of Virtual Tree that bound to DataRowView objects. Changes in .NET 2.0 meant that this approach no longer works. Instead Virtual Tree now binds directly to the Row objects. So the code should be something like:

Code:
private void _virtualTree_GetChildren(object sender, GetChildrenEventArgs e)
{
    RowBinding binding = _virtualTree.GetRowBinding(e.Row);
    if (binding == this.rowBindingCustomers)
    {
        DataRowView drv = e.Row.Item as DataRowView;
        DataView dv1 = drv.CreateChildView("CustomersOrders");
        DataView dv2 = drv.CreateChildView("CustomersInquiries");
        DataRow[] children = new DataRow[dv1.Count + dv2.Count];
        int i = 0;
        foreach (DataRowView drv in dv1)
        {
             children[i++] = drv.Row;
        }
        foreach (DataRowView drv in dv2)
        {
             children[i++] = drv.Row;
        }
        e.Children = children;
    }
    else
    {
        e.Children = binding.GetChildrenForRow(e.Row);
    }           
}

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
dinabandhu



Joined: 19 Sep 2007
Posts: 9

PostPosted: Fri Sep 21, 2007 9:25 am    Post subject: Reply with quote

Thanks for a quick reply.

I have made some modifications to your code. Instead of putting the code in tree's getchildren event i have put it in individual binding's getchildren event. This seems to work and code is slightly cleaner. I hope this is correct.

What i am concerned about is the effect of the copying on standard databinging features ... specifically

1. If i update a field from the tree will the change still percolate to the core dataset and subsequently to the database?
2. If I insert/update/delete a row into the dataset directly will it still update the tree automatically or I need to write code for that?

I will try this out anyway but your advice on this would be usefull.

Regards,

Dinabandhu
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Sep 21, 2007 10:20 pm    Post subject: Reply with quote

Quote:
I have made some modifications to your code. Instead of putting the code in tree's getchildren event i have put it in individual binding's getchildren event. This seems to work and code is slightly cleaner. I hope this is correct.


That's correct. When the original code posted was written the individual binding GetChildren event did not exist.

Quote:
1. If i update a field from the tree will the change still percolate to the core dataset and subsequently to the database?


This should be OK - because the rows you are binding to "know" they are part of a table and dataset - so updates to them will still be handled in the same way.

Quote:
2. If I insert/update/delete a row into the dataset directly will it still update the tree automatically or I need to write code for that?


This may not work because you are now bound to a list not the actual dataviews. The simple solution is to simply call Tree.UpdateRows programmatically in this case. A more complicated (but possibly better) solution is to create a wrapper class that contains the two child DataView objects and implements the IBindingList interface to retrieve the row at a given composite index. It could handle the IBindingList.ListChanged events coming from the child DataViews and pass these on to its clients. We already have a wrapper class DataViewList that does this for a single DataView.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group