Hide/Remove LoadLayout Column

2 posts, 0 answers
  1. Paul
    Paul avatar
    24 posts
    Member since:
    Aug 2015

    Posted 29 Jul Link to this post

    I am calling LoadLayout on a RadGridView then using a factory class todynamically gets the properties of an object passed in and determines what properties should be shown. Based on what properties should be shown, the factory adds columns if they don't exist from the LoadLayout or  gets the column if it does exist and configures it. But if a column was created from the LoadLayout and there is no property associated with it anymore, I need to hide or remove the column.

    Based on other forum posts, I've tried:

    if (gridView.MasterTemplate.Columns.Contains(name)) // returns false
        var col = gridView.MasterTemplate.Columns[name];
        col.VisibleInColumnChooser = false;
        col.IsVisible = false;
    if (gridView.Columns.Contains(name)) // returns false
        var col = gridView.Columns[name];
        col.VisibleInColumnChooser = false;
        col.IsVisible = false;

    If I break after the code above runs, I can see that the column is not longer in the the gridView's column collection, but when its rendered the column is displayed. How do I hide or remove a column immediately after calling LoadLayout?

  2. Dimitar
    Dimitar avatar
    1321 posts

    Posted 01 Aug Link to this post

    Hello Paul,

    Thank you for writing.

    You approach for removing the column is correct, however, the column may still not be on the grid when this code is executed. This is why the proper place to do that would be the LayoutLoaded event handler. Could you please try using this event for the column removing and let me know the results on your side.  

    I hope this will be useful. 

    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. DevCraft R3 2016 release webinar banner
Back to Top