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

How to Get GridViewColumn Name

2 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Elke
Top achievements
Rank 1
Elke asked on 03 Aug 2010, 10:46 PM
Hi I am looking for how to retrieve a GridViewColumn Name from the codebehind.

In my code we were using a conditional to check if the Header matched a certain value, but we are adding tooltips to the column header so now I'm using the following format to set the header, which causes my conditional to never find the column header.

if (e.GridViewDataControl.Columns[i].Header.ToString().Equals("Color"))
is what I was using

The xaml looks like this:
<telerikgrid:GridViewDataColumn Width="50" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}" x:Name="colColor">
  <telerikgrid:GridViewDataColumn.Header>
    <TextBlock x:Name="txtColor" Text="Color"/> 
  </telerikgrid:GridViewDataColumn.Header
</telerikgrid:GridViewDataColumn>

Can I access the column by the name?

2 Answers, 1 is accepted

Sort by
0
Accepted
Chris
Top achievements
Rank 1
answered on 03 Aug 2010, 11:20 PM
You could use the UniqueName property like this:

if (e.GridViewDataControl.Columns[i].UniqueName.Equals("Color"))

and

<telerikgrid:GridViewDataColumn Width="50" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle1}" x:Name="colColor" UniqueName="Color">
  <telerikgrid:GridViewDataColumn.Header>
    <TextBlock x:Name="txtColor" Text="Color"/>
  </telerikgrid:GridViewDataColumn.Header>
</telerikgrid:GridViewDataColumn>

- Chris
0
Elke
Top achievements
Rank 1
answered on 04 Aug 2010, 02:10 PM
This works fantastically, thanks!
Tags
GridView
Asked by
Elke
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Elke
Top achievements
Rank 1
Share this question
or