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

How to hide a column?

1 Answer 168 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Todd Davis
Top achievements
Rank 1
Todd Davis asked on 24 Mar 2010, 07:28 PM
This seems like it should be an easy thing, but I'm hitting roadblocks all over the place.

I have a RadGridView inside of a User Control that I use on more than one page. The first column of the RadGridView is a GridviewSelectColumn, however, in certain situations, I don't want this column to appear.

The first thing I tried to do was Name it, then hide it:
<grid:GridViewSelectColumn x:Name="SomeName" />
(in Load Event)
SomeName.IsVisible = false;

But this fails because SomeName always comes up as null.

Then I tried creating a public property and trying to bind it to the column:

<grid:GridViewSelectColumn IsVisible="{Binding IsHidden}" />
(in code behind)
public bool IsHidden{ get; set; }

This did not seem to work either.

How the heck do I hide this conditionally?

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 25 Mar 2010, 07:52 AM
Hi,

You cannot access grid columns by Name since columns are not FrameworkElements. Again because of this you cannot bind column properties since Binding is supported only for FrameworkElements - grid columns are plain DependencyObjects. You can access this column however using grid columns collection - by UniqueName, by index or even by type:

var column = RadGridView1.Columns["YourUniqueName"];

or

var column = RadGridView1.Columns[0];

or

var column = RadGridView1.Columns.OfType<GridViewSelectColumn>().FirstOrDefault();


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
Todd Davis
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or