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 

Apply Filter in DataTable

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



Joined: 07 Nov 2007
Posts: 24

PostPosted: Tue Apr 27, 2010 9:08 am    Post subject: Apply Filter in DataTable Reply with quote

Hi Infralution Group,

I have a small problem in applying filter when use a DataSet as tree datasource.
let's see the example, I have a DataSet with two tables A and B, Relation relation_A_B(A as parent of B). In the tree I have two Levels, Level 1 displays Table A, level 2 displays Table B.
here I would like to apply a filter in a column Active of B. after I set B.DefautlView.RowFilter = "Active = 'True'", it doesn't work. but in Table A it works.
Could you please give some suggestion on this topic?

BTW, for now I use method ReloadChildren to filter Table B, but this has some disadvantage when Table B changes.

thank you in advance.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Apr 28, 2010 1:01 am    Post subject: Reply with quote

The DataRowRowBinding class finds the children for a given parent row by calling DataRowView.CreateChildView(relation). This creates a separate DataView based on the parent/child relation. Setting the RowFilter on the DefaultView will not affect these child DataViews. To implement filtering on child rows you need to set the filter on these DataViews when they are created. To do this you can handle the GetChildren event and use the default RowBinding method to get the children. Then extract the underlying DataView and set the RowFilter (see below). Note that the DataRowRowBinding adds a DataViewList wrapper around the underlying child DataView. The code below sets a filter on Orders table of the DataSet Browser sample project.

Code:
private void _virtualTree_GetChildren(object sender, GetChildrenEventArgs e)
{
    RowBinding rowBinding = _virtualTree.GetBindingForRow(e.Row);
    e.Children = rowBinding.GetChildrenForRow(e.Row);
    if (e.Row.Item is OrderDataSet.CustomersRow)
    {
        DataViewList dvl = e.Children as DataViewList;
        dvl.DataView.RowFilter = "ShipName LIKE 'B*'";
    }
}


If the filter changes you would need to call VirtualTree.UpdateRows(true) to force VirtualTree to reload the child data views with changed filters.
_________________
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