Articles in this section
Category / Section

How to bind WPF DataGrid (SfDataGrid) with CollectionViewSource?

1 min read

You can bind CollectionViewSource instead of binding an IEnumerable collection in WPF DataGrid (SfDataGrid). You have to create the view from CollectionViewSource using GetDefaultView method like below code example.

XAML

<Syncfusion:SfDataGrid x:Name="datagrid"
                               AutoGenerateColumns="False"
                               ItemsSource="{Binding Employee}">
            <Syncfusion:SfDataGrid.Columns>
                <Syncfusion:GridTextColumn MappingName="EmployeeName" />
                <Syncfusion:GridTextColumn MappingName="EmployeeAge" />
                <Syncfusion:GridTextColumn MappingName="EmployeeGender" />
                <Syncfusion:GridComboBoxColumn DisplayMemberPath="Country"
                                               ItemsSource="{Binding ProductsView,
                                                                     Source={StaticResource country}}"
                                               MappingName="CountryCode"
                                               SelectedValuePath="CountryCode" />
                <Syncfusion:GridCheckBoxColumn MappingName="Review" />
            </Syncfusion:SfDataGrid.Columns>
</Syncfusion:SfDataGrid>

C#

private void InitialiseProductOptionsView()
{
    Employee = CollectionViewSource.GetDefaultView(GDCSource);
    ProductsView = CollectionViewSource.GetDefaultView(Country);
}

View sample in GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied