
- Do you always have to specify a Columns collection? I mean, because I can have many different reports for the same GridView, I want to be able to show them all without having to specify the columns individually.
- How do you programatically hide or show a column at a specific index or with a specific header? My user wants to be able to hide some columns before exporting the report results, so I'm planning on showing him a CheckBox list with the columns, so he can choose which ones to show/hide.
Thanks a lot.
5 Answers, 1 is accepted
There is no need to define columns collection if you do not need to. You can use the property of RadGridView AutoGenerateColumns and set it to "true". Thus the columns will be based on the properties of the data item it is bound to. A column is created for every public property of simple type (integer, string, date, enum and boolean).
As for your second question, you can hide or show programatically a column with a specific index. If you want to use Check Boxes, you may add the following lines when each one is checked:
this.RadGridView1.Columns[1].IsVisible = false;
Where the index in Columns[ ] specifies the column you want to hide or if it is set to "true" - to show.
I hope that helps.
Best wishes,
Maya
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.

What if I want to hide the nest grids columns, my datasource has tables linked and I just dump them in the grid (don't know what will be in them at design time) Please let me know how I can do that in the code behind
You can use DataLoading/AutoGeneratingColumn events to assess auto-generated child grid columns or you can define directly desired child grid columns using HierarchyChildTemplate. You can check this demo for more info.
Best wishes,Vlad
the Telerik team

Thank you
//this works because it can see the parent table's columns
if (e.Column.Header.ToString().ToUpper() == "BLOCK_ID")
{
e.Column.IsVisible =
false;
}
You can subscribe to AutoGeneratingColumn for child tables using DataLoading:
var grid = (GridViewDataControl)sender;
if(grid.ParentRow != null)
{
grid.AutoGeneratingColumn += ...
}
Vlad
the Telerik team