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

GridView Hide Certain Columns

1 Answer 763 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sravanthi
Top achievements
Rank 1
Sravanthi asked on 26 Nov 2012, 07:54 PM
Hey,  I have a gridview where, i am binding it as follows ::
grdView.DataSource = dsNames;
The datasource 'dsNames' has 10 columns and, I want to only show 2 columns in the grid. how do i do that?

Also, i tried adding the 2 required columns in the designer and set the auto generatecolumns to false. If i do it this way, no data is displayed. 

Please let me know how to do binding.

Thanks,
Sri

1 Answer, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 29 Nov 2012, 05:11 PM
Hi Sravanthi,

Thank you for writing.

If you leave the grid to auto generate the columns automatically, you can use the IsVisible property of a column to hide it. I would suggest using the DataBindingComplete event of RadGridView to manipulate with the columns, since this way you will be sure that they will exist when you attempt to access them
grdView.Columns["Column name"].IsVisible = false;

Setting the AutoGenerateColumns property to false allows you to add the desired columns manually and link them to the data source. In your case, I assume that the FieldName of the columns is not set, thus the data is not displayed. 

I hope you find my answer helpful. Let me know if you have any further requirements.

Kind regards,
Plamen
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
GridView
Asked by
Sravanthi
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or