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

[Solved] Searching for Hidden column throws error

1 Answer 55 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dave
Top achievements
Rank 1
Dave asked on 05 Jul 2011, 07:16 PM
I've got a RadGridView with too many entries in it, and a setup form to allow my users to decide which columns to see.

I have a default setup with a bunch of columns hidden, and then when the setup form is saved, I spin through and set all my columns IsVisible = false then spin through the list of columns they've selected:

for (int j = 0; j < obj.Count; j++)
{
    GridViewColumn gvc = gvMyWork.Columns[obj[j].DisplayName];
    gvc.IsVisible = obj[j].IsSelected;
    gvc.DisplayIndex = obj[j].DisplayOrder;
}

This works great for columns that are visible when the code is exercised, but for columns that are not visible I get a null return in gvc.

If this doesn't work, what is the correct way to find a column by name if it is hidden?

Thanks!

-Dave

1 Answer, 1 is accepted

Sort by
0
Dave
Top achievements
Rank 1
answered on 05 Jul 2011, 08:40 PM
I found the error of my ways on this one... sorry for the confusion.

For anyone else having similar problems... I needed to be using the field name, not the display name in the header. For instance, the field name I was trying to use was "CreatedBy", and the 'display name' in the header was "Created By".

When I woke up and used "CreatedBy" in the code, it found it just fine:

for (int j = 0; j < obj.Count; j++) 
    GridViewColumn gvc = gvMyWork.Columns[obj[j].FieldName]; 
    gvc.IsVisible = obj[j].IsSelected; 
    gvc.DisplayIndex = obj[j].DisplayOrder; 
}

-Dave
Tags
GridView
Asked by
Dave
Top achievements
Rank 1
Answers by
Dave
Top achievements
Rank 1
Share this question
or