View previous topic :: View next topic |
Author |
Message |
shashi
Joined: 05 Dec 2007 Posts: 6
|
Posted: Tue Feb 17, 2009 4:05 pm Post subject: Virtual tree filter |
|
|
Hi,
I am using databinding to display the rows in the virtual tree.I want to filter the rows displayed for the virtual tree, hence i am applying filter to the datasource of the virtual tree,here the datasource is of type bindingsource.
After applying filter on the datasource variable of the virtual tree that is of type binding source,i called the methods resetbindings() on the datasource variable.
Virtual tree is not able to reload the filtered data.
Code structure :
taxMasterBindingSource.Filter = _filterString; //here vtTaxMaster.datasource=taxMasterBindingSource,_filterString is some valid filter string
taxMasterBindingSource.ResetBindings(false);
vtTaxMaster.UpdateRows(true);
vtTaxMaster.Update();
Can u suggest me some way out? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Feb 17, 2009 10:09 pm Post subject: |
|
|
The BindingSource.Filter property only works if you have set the BindingSource.DataSource to a DataView (not a DataSet or DataTable). The MSDN documenation says:
Quote: | Typically used in complex data-binding scenarios, the Filter property allows you to view a subset of the DataSource. Only underlying lists that implement the IBindingListView interface support filtering. |
If your BindingSource.DataSource is a DataSet or DataTable you can still filter the data - however you need to set the RowFilter on the underlying DataView instead of setting the BindingSource.Filter. For example in the Data Set Browser sample project I could filter the customers by doing the following:
Quote: | _dataSet.Customers.DefaultView.RowFilter = "CompanyName LIKE 'C*'"; |
_________________ Infralution Support |
|
Back to top |
|
|
shashi
Joined: 05 Dec 2007 Posts: 6
|
Posted: Wed Feb 18, 2009 8:10 am Post subject: |
|
|
Thanks a lot ,the idea suggested by you is working.But as mentioned by you
Only underlying lists that implement the IBindingListView interface support filtering.
But BindingSource implements IBindingListView ,then y the filteration cannot be done directly on the BindingSource.
Please have a look on this. |
|
Back to top |
|
|
shashi
Joined: 05 Dec 2007 Posts: 6
|
Posted: Fri Feb 20, 2009 7:31 am Post subject: Child virtual tree sort |
|
|
Details:
MasterTable named as MTable
ChildTable named as CTable (linked to the MTable through a relation)
vtree1 has to show rows from MTable
vtree2 has to show rows from CTable(following to the parent relation)
Requirement for my desing was to have two virtual trees,where the first virtual trees shows all the rows from the MasterTable named as MTable and second virtual tree shows only the
rows that satisfiles the relation between the Master table and child table.
So, what i m doing is:
1.I have set the datasource for the first virtual tree to the dataset table MTable through a bindingsource,also as i dont want to show the child rows in the first virtual tree hence i have
removed the child property for the first virtual tree.
2.In the second virtual tree what i m doing is that i have set the datasource property to the Parent table,and as i only want to show the child rows ,i have deleted the cell bindings from
the databindings for the parent table.This step is only done to generate the appropriate databindings,when the databindigs are generated the datasource property for the second tree is
reset.
3.In the selection change event of the first tree i m setting the datasource property for the second tree by writing the code
virtualtree2.Datasource=Virtualtree1.selecteditem;
As the datasource for the first virtual tree is set to a datable the idea suggested by you is working fine for the virtual tree
that is if i m applying filter for for the datatable as
datatable.TableName.DefaultView.RowFilter = _filterString;
dsTaxPlan.MTable.DefaultView.RowFilter = _filterString;
but if i am doing the same for the second virtual tree filtering is not happening.
dsTaxPlan.CTable.DefaultView.RowFilter = _filterString;
Can u tell me a way out? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Feb 20, 2009 8:06 am Post subject: |
|
|
When you set the Children property to a Relation in a DataRowRowBinding Virtual Tree Data uses the DataSet Relation to get the children for the parent row. To do this it uses the DataRowView.CreateChildView method. This means it is not using the DefaultView so setting the filter on the DefaultView won't filter the children. To do this you can handle the GetChildren event for the parent DataRowRowBinding (in your case for the MTable) and set the filter on the underlying Child DataView created by the binding. The sample code below demonstrates filtering the child orders for a customer in the sample Data Set Browser project:
Code: |
private void rowBindingCustomers_GetChildren(object sender, GetChildrenEventArgs e)
{
DataViewList dvl = rowBindingCustomers.GetChildrenForRow(e.Row) as DataViewList;
dvl.DataView.RowFilter = "Freight > 10.00";
e.Children = dvl;
} |
_________________ Infralution Support |
|
Back to top |
|
|
|