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

Hide/Remove LoadLayout Column

1 Answer 157 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 29 Jul 2016, 05:10 PM

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:

gridView.MasterTemplate.Columns.Remove(name);
gridView.Columns.Remove(name);
 
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?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 01 Aug 2016, 08:03 AM
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. 

Regards,
Dimitar
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.
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or