RadDataGrid auto generate column mode bug with sorting

3 posts, 1 answers
  1. Petr
    Petr avatar
    5 posts
    Member since:
    Jul 2019

    Posted 25 Aug 2019 Link to this post


    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,


  2. Answer
    Yana avatar
    4962 posts

    Posted 28 Aug 2019 Link to this post

    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.

    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
  3. Petr
    Petr avatar
    5 posts
    Member since:
    Jul 2019

    Posted 28 Aug 2019 in reply to Yana Link to this post

    Hi Yana,

    Thank you very much for answer!

    It was helpful!

Back to Top