Skip to main content

DevExpress v24.1 Update — Your Feedback Matters

Our What's New in v24.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Bind the WPF Data Grid to ICollectionView

  • 2 minutes to read

The GridControl allows you to sort, group, and filter data at the control level. If you bind the grid to an ICollectionView, you can perform these data shaping operations at the data source level.

We recommend that you use ICollectionView in the following cases:

  • You perform data shaping operations at the collection level and share these settings across multiple controls.
  • Synchronize row selection across multiple controls.
  • You manage multi-thread updates.

To bind the GridControl to ICollectionView, assign the source collection to the DataControlBase.ItemsSource property.

Set the DataViewBase.IsSynchronizedWithCurrentItem property to true to synchronize the focused row with the current item in ICollectionView.

Run Demo: CollectionView

<dxg:GridControl x:Name="grid" ItemsSource="{Binding CollectionView}">
    <dxg:GridControl.View>
        <dxg:TableView IsSynchronizedWithCurrentItem="True">/>
    </dxg:GridControl.View>
</dxg:GridControl>
public class CollectionViewViewModel : BindableBase {
    IList employeesCore = EmployeesWithPhotoData.DataSource;
    public IList Employees { get { return employeesCore; } }
    public ICollectionView CollectionView { get; private set; }

    public CollectionViewViewModel() {
        CollectionView = new CollectionViewSource() { Source = Employees }.View;
        CollectionView.GroupDescriptions.Add(new PropertyGroupDescription("JobTitle"));
        CollectionView.SortDescriptions.Add(new SortDescription("JobTitle", ListSortDirection.Ascending));
        CollectionView.MoveCurrentToFirst();
    }
}

View Example: Synchronize the WPF Data Grid with the ICollectionView

#Limitations

If you bind the GridControl to ICollectionView, the control works in Server Mode. Refer to the following topic for information on Server Mode Limitations. To avoid these limitations, set AllowCollectionView to false. In this case, the GridControl performs data operations on its own.