This project is read-only.
1
Vote

ExtendedDataGrid SortDescription exception

description

Hi,

I am using ExtendedDataGrid to display data. I need to display the data sort by Name by default.
I am using ICollectionView for data binding. I am adding SortDescription to sort based on the Employee Name by default.

I am getting following exception while loading the view.

System.Windows.Markup.XamlParseException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
<wpfExtDataGrid:ExtendedDataGrid x:Name="ExtendedGrid" ItemSoource = "{Binding CollectionViewList}" >
<wpfExtDataGrid:ExtendedDataGrid.Columns>

                        <Custom:DataGridTextColumn x:Name="EmpId"
                                                   Header="EmpId"
                                                                                                                Width="2*"
                                                                                                                Binding="{Binding EmpId}"
                                                                                                                IsReadOnly="True"/>

                        <Custom:DataGridTextColumn x:Name="Name"
                                                   Header="Name"
                                                                                                                Width="*"
                                                                                                                Binding="{Binding Name}"
                                                                                                                IsReadOnly="True" />

                    </wpfExtDataGrid:ExtendedDataGrid.Columns>
</wpfExtDataGrid:ExtendedDataGrid>
Public class EmployeeViewModel
 {
 public EmployeeViewModel ()
    {
        EmployeeDetails = new List<Employee>();

                            for (int i = 10; i > 0; i--)
            {
                            EmployeeDetails.Add(new Employee
                            {
                                            EmpId = i,
                                            Name = i + "Name"
                            });
            }

        CollectionViewList = CollectionViewSource.GetDefaultView(EmployeeDetails);
        CollectionViewList.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
    }

    public ICollectionView CollectionViewList { get; set; }

    private ObservableCollection<Employee> _employeeDetails;

    public ObservableCollection<Employee> EmployeeDetails
    {
        get { return _employeeDetails; }
        set { _employeeDetails = value; }
    }
}
Regards,
Sharda

comments