This is a migrated thread and some comments may be shown as answers.

RadDataGrid auto generate column mode bug with sorting

2 Answers 70 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Petr
Top achievements
Rank 1
Petr asked on 25 Aug 2019, 07:21 PM

Hello!

I'm using a datagrid bound to an observable collection with AutoGenerateColumns mode.
I found bug. Description is here:
1) DataGrid bounded to object with 5 properties, so datagrid will have 5 columns.
2) When i start apllication, I set 4 columns to true, 1 last column to false.

3) I open ColumnChooser and set last column visible check box to True. It is ok. Instantly last column will be appeared in the table.

4) Problem is here: If I click some column to header and sorting method will be called -> my datagrid will be sorted but last column will disapper. And if I open columChooser i will see that CheckBox of last column is uncheched. As result I get sorted grid without all columns, which I add by columnChooser.

I don't know how to fix this. Can you help me with that ?

I attached sample project with this issue. Link: https://dropmefiles.com/ihHqU

Thank you,

Petr

2 Answers, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 28 Aug 2019, 10:57 AM

Hi Petr,

Thank you for providing the sample. 

The reason for the observed behavior is that last column visibility is changed inside the DataBindingComplete event handler.  Please note that DataBindingComplete event occurs when the ItemsSource has been successfully bound to the control or any data operation like Group, Sort or Filter is applied.

I guess you need to update the column visibility only after the initial data load. To achieve this, you could just unsubscribe from the DataBindingComplete event like this:

private void DataGrid_DataBindingComplete(object sender, Telerik.UI.Xaml.Controls.Grid.DataBindingCompleteEventArgs e)
{
    var colNames = new string[]{ "Id", "Name", "Surname", "Salary" };
            
    foreach (var column in dataGrid.Columns)
    {
        var name = column.GetType().GetProperty("PropertyName").GetValue(column);
        column.GetType().GetProperty("Name").SetValue(column, name);
        column.IsVisible = false;
    }

    foreach(var name in colNames)
    {
        dataGrid.Columns[name].IsVisible = true;
    }

    dataGrid.DataBindingComplete -= DataGrid_DataBindingComplete;
}

I hope I was of help.

Regards,
Yana
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Petr
Top achievements
Rank 1
answered on 28 Aug 2019, 02:02 PM
Hi Yana,

Thank you very much for answer!

It was helpful!

Petr.
Tags
DataGrid
Asked by
Petr
Top achievements
Rank 1
Answers by
Yana
Telerik team
Petr
Top achievements
Rank 1
Share this question
or