wpf-11124-controls-and-libraries-data-grid-bind-to-data-bind-to-icollectionview.md
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:
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.
<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();
}
}
Public Class CollectionViewViewModel
Inherits BindableBase
Private employeesCore As IList = EmployeesWithPhotoData.DataSource
Public ReadOnly Property Employees As IList
Get
Return employeesCore
End Get
End Property
Public Property CollectionView As ICollectionView
Public Sub New()
CollectionView = New CollectionViewSource() With {
.Source = Employees
}.View
CollectionView.GroupDescriptions.Add(New PropertyGroupDescription("JobTitle"))
CollectionView.SortDescriptions.Add(New SortDescription("JobTitle", ListSortDirection.Ascending))
CollectionView.MoveCurrentToFirst()
End Sub
End Class
View Example: Synchronize the WPF Data Grid with the ICollectionView
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.