Carlos Blanco
Carlos Blanco

Reputation: 8762

Telerik RADGrid and identifying columns

I'm adding columns to the RADGrid in the following way.

grid.Columns.Add(
                new GridViewDataColumn
                    {
                        Name = name,
                        Header = header,
                        DataMemberBinding = new Binding(item),

                    });

I tried to set the Name property to an Id value that use to track them. However, I got an execption saying that 0 -- in my case -- was not a valid value for Name. Is there some property I can use to identify the columns later? I thought Name could be use in the same way as in Java Swing :P

EDIT: (from comments)

I have an ObservableCollection of dynamic objects that I track and contain all the info coming from DB. In this info coming from DB, there are ColumnID and Column Name. I saw this code(above) in the application to add columns at run time to the RADGrid. It only sets the Column Names. I want to perform some action when the DoubleClick event of the RadGrid occurs. I need to identify what column the user clicked on. Since columns could have the same name, I wonder if there is a way to store the Column Id somewhere in the GridViewDataColumn.

Upvotes: 0

Views: 1082

Answers (1)

CodingGorilla
CodingGorilla

Reputation: 19842

To answer this question specifically:

Is there some property I can use to identify the columns later?

Your best bet is to save (maybe use a Dictionary) and use the column index to be able to find this column again. You can always do:

grid.Columns[index]

To access the column and do your work later.

Upvotes: 2

Related Questions