Skip to main content
A newer version of this page is available. .

Bind the WPF Data Grid to ICollectionView

  • 2 minutes to read

Run Demo: CollectionView

The GridControl supports ICollectionView binding. To bind the GridControl to the ICollectionView, assign the source collection to the grid’s DataControlBase.ItemsSource property and enable the DataViewBase.IsSynchronizedWithCurrentItem option. The grid automatically synchronizes its grouping, sorting, current item, and can directly change the underlying collection.

<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();
    }
}

Example: Bind the WPF Data Grid to ICollectionView

Limitations

When the GridControl is bound to a collection view, the grid functions in the Server Mode. Refer to the following topic for information on its limitations: Server Mode Limitations.

When working with ICollectionView sources, the GridControl delegates all data management operations (sorting, filtering, grouping) to ICollectionView, which imposes some limitations on the GridControl‘s features. You can overcome all ICollectionView limitations. Set the GridControl.AllowCollectionView property to false to let the GridControl perform all data management operations.