We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding to a ICollectionView

Thread ID:

Created:

Updated:

Platform:

Replies:

95519 Jul 15,2010 01:41 AM UTC Feb 28,2011 07:48 AM UTC WPF 10
loading
Tags: GridControl
Scott Kobetis
Asked On July 15, 2010 01:41 AM UTC

I am trying to bind the ICollectionView of an ObservableCollection to a GridDataControl. I do this because I want to filter the collection before binding it to the grid.

It seems that the GridDataControl binds directly to the SourceCollection view on the ICollectionView which means any filtering I apply to the view is ignored.

My questions are:
a) Why is this implemented like this and how can I bind to the view?
b) If it's not possible to bind to the view, how can I filter my collection before displaying it in the grid?

Thanks.

Jeraldes J [Syncfusion]
Replied On July 17, 2010 07:43 AM UTC

Hi Scott,

You can use the filtering internally in the xaml and through code behing. As the filtering will be used at the loading itself.

Please refer the following sample code for filtering in the loading time.

XAML:








Code Behind:
void dataGrid_Loaded(object sender, RoutedEventArgs e)
{
dataGrid.Model.View.BeginInit();
var fc = (from vc in this.dataGrid.VisibleColumns where vc.MappingName == "CompanyName" select vc).First();
FilterPredicate fp = new FilterPredicate();
fp.FilterType = FilterType.StartsWith;
fp.PredicateType=PredicateType.And;
fp.FilterValue = "A";
fp.IsCaseSensitive = false;
fc.Filters.Add(fp);
dataGrid.Model.View.EndInit();
}


Regards,
Jeraldes J

Scott Jeslis
Replied On August 3, 2010 10:59 PM UTC

I have the same need but I don't I know on control load time which of 3 particular filters my users want.

Scott Jeslis
Replied On August 3, 2010 11:27 PM UTC

Similar Filter Predicate code worked for me in the code behind (without the BeginInit & EndInit) based on the state of a toggle.

I was using MVVM so the code behind is not where I desired to do this at.

Additionally, can the filtering be done on an invisible column?

Jeraldes J [Syncfusion]
Replied On August 6, 2010 08:30 AM UTC

Hi Scott,

You can use the manual XAML filtering internally by setting the filter predicated. In that set the Filter type, filter value and case sencitive internally in the XAML. Filtering will be done in the loaded itself.
You can set the filtering to the invisible column also by setting isHidden = true to the visual column.

Please refer the following sample code for filtering in the loading time.

XAML:









Please download the sample from the below link:
http://www.syncfusion.com/uploads/redirect.aspx?file=GCD-FilterWhileLoading-95519_e02b25ac.zip&team=development
Let us know if you face any other issues.

Regards,
Jeraldes J

Scott Kobetis
Replied On August 18, 2010 12:41 AM UTC

How can I filter on a field in my collection that is not set as a visible column?

Jeraldes J [Syncfusion]
Replied On August 20, 2010 12:46 PM UTC

Hi Scott,

We have developed a sample with the filter predicates that will filter the filed that is not in the VisibleColumn. Please refer the code snipped.

Code Snippet:
this.dataGrid.Model.Initialized += new EventHandler(Model_Initialized);

void Model_Initialized(object sender, EventArgs e)
{
ICollectionView view = this.dataGrid.Model.View;
view.Filter += new Predicate(ShowFilteredOrdersList);
}

private bool ShowFilteredOrdersList(object item)
{
Orders ord = item as Orders;

if (ord.ShipRegion == "DF")
return true;
else
return false;

}

Please download the sample from the below link.


http://www.syncfusion.com/uploads/redirect.aspx?file=GCD-FilterWithoutVisualColumn-95519_be651fdf.zip&team=development

Let us know if you need any other details.

Regards,
Jeraldes J
Scott Kobetis
Replied On August 30, 2010 01:41 AM UTC

Hi,
This works well until I try to add a grouped column in code. This resets the filter and reverts to displaying all items.

Any ideas?

Scott

Jeraldes J [Syncfusion]
Replied On August 31, 2010 10:01 AM UTC

Hi Scott,

When you want the data to be filtered and displayed at the time of removing the grouping, you have to use the GroupedColumns.Changed event to check with the filter to be set. This would set with the filer when ungrouping. Please refer with the sample code snippet from below.

[Code Snippet]
this.dataGrid.GroupedColumns.Changed += new EventHandler(GroupedColumns_Changed);

void GroupedColumns_Changed(object sender, EventArgs e)
{
ICollectionView view = this.dataGrid.Model.View;
view.Filter += new Predicate(ShowFilteredOrdersList);
}

And download the sample from the below link.

http://www.syncfusion.com/uploads/redirect.aspx?file=GCD-FilterWithoutVisualColumn-95519_213575e.zip&team=development

Let us know if you need any other details.

Regards,
Jeraldes J

Mauricio Feijo
Replied On February 19, 2011 02:52 PM UTC

So, Jeraldes, are you saying the fact that changing the grouping resets all fitering is BY DESIGN? Not a bug? Could we hear the rationale behind that design decision?

Also, twice on this discussion you advise to check your code snippet for an example of how to filter by a column that is NOT in the visible columns collection, but fail to really demonstrate that in the code.


Manikandan [Syncfusion]
Replied On February 28, 2011 07:48 AM UTC

Hi Mauricio,

Regarding the Filter :The Grid will maintain the single view to display all the possibilities, the Filtering will work on the Flat view. When the source was grouped by some constraints then view will be recreated in which only the group header will be in visible and then by expanding the view will be created again to display the expanded item. The group header will also considered as a record in the view, so we can’t apply the fitter to the view in which the records are all not homogenous.

Regarding the filter in hidden column: We have create a sample for this please find the sample in the following location, In this sample we have filtered the view based on the values appeared in the hidden column.

Sample :
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GDC_Invisible1230227542.zip

Please let us know if you have any queries.

Thanks,
Manikandan J R.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;