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

Hide or show columns

5 Answers 1607 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hugo Aristizabal
Top achievements
Rank 2
Hugo Aristizabal asked on 12 May 2010, 12:09 AM
Hi. I'm developing a form on which the user can select one of many reports to show, and I have two questions on the GridView:

  1. 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.
  2. 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

Sort by
0
Accepted
Maya
Telerik team
answered on 12 May 2010, 05:51 PM
Hi Hugo Aristizabal,

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.
0
Tarik
Top achievements
Rank 1
answered on 10 Sep 2010, 06:46 PM
Hello,

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
0
Vlad
Telerik team
answered on 13 Sep 2010, 07:23 AM
Hi,

 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
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
0
Tarik
Top achievements
Rank 1
answered on 13 Sep 2010, 04:25 PM
Thanks for the reply, the AutoGeneratingColumn event doesn't do the job. My parent table has 3 columns, so the event gets fired 3 times. I am able to capture the columns from the event handler via the code below but I'm interested in capturing the children grids. Thank you for sending the example but I'm not sure it's what I need as I don't know what the child tables will look like (sometimes they might have 10 columns others 15). Could you please show me a code example of deleting child columns?

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;

 

}

0
Vlad
Telerik team
answered on 13 Sep 2010, 04:39 PM
Hi,

 You can subscribe to AutoGeneratingColumn for child tables using DataLoading:

var grid = (GridViewDataControl)sender;
if(grid.ParentRow != null)
{
grid.AutoGeneratingColumn += ...
}

Regards,
Vlad
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
Tags
GridView
Asked by
Hugo Aristizabal
Top achievements
Rank 2
Answers by
Maya
Telerik team
Tarik
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or