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

[Solved] AutoGenerateColumns and their order

8 Answers 251 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 24 Apr 2009, 05:13 PM
Hi, I am creating a grid using autogenerated columns and the problem I am having is that the columns are not being created in the order that they are being returned in the the dataset. I need them to be created in a certain sequence because it is supposed to be a report and the columns are dollar ranges.

Also, in the ColumnCreated event I am trying to figure out how to view the index of the column. I do not know the unique names and need to access these columns by their index. Every time I try to access OrderIndex the value is -1. Am I missing something here?

So,

#1 - how can I guarantee that the autogenerated columns will be created in a particular sequence (based on how they are ordered/returned in the dataset)

#2 - how can I access a column in the ColumnCreated event by its index?

Thanks.

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Apr 2009, 04:04 AM
Hello Darren,

The UniqueNames for AutoGenerated columns are the same as the DataField names in the DataSet. So you can access the Columns in the ColumnCreated event using their UniqueNames as shown below:
c#:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.SwapColumns("DataField2""DataField1"); 
    } 

Thanks
Princy.
0
Darren
Top achievements
Rank 1
answered on 25 Apr 2009, 05:07 AM
I don't know the unique names OR the data field names because they are being returned dynamically from sql server - I don't know what they are in advance, so this will not work for me. Thanks.
0
Shinu
Top achievements
Rank 2
answered on 25 Apr 2009, 08:25 AM
Hi Darren,

Try accessing the OrderIndex of the column in the PreRender event as shown below.

CS:
 
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            if (col != null)  
            { 
                int colIndex = col.OrderIndex; 
            } 
        } 
    } 


Shinu.
0
Darren
Top achievements
Rank 1
answered on 25 Apr 2009, 02:23 PM
Hi, Sorry but I think you guys lost track of what I am trying to do and I still don't know how to do it.
"...in the ColumnCreated event I am trying to figure out how to view the index of the column..". Thanks.
0
Iana Tsolova
Telerik team
answered on 27 Apr 2009, 07:24 AM
Hi Darren,

You can get the column index as below:

C#
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)  
{  
    int index = e.Column.OrderIndex;  

Note that GridExpandColumn and GridRowIndicatorColumn are always in front of data columns, so column indexs start at index 2. 

Greetings,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Darren
Top achievements
Rank 1
answered on 27 Apr 2009, 02:32 PM
Hi, When I was checking these values they were always -1, but I will check again. Thanks.
0
Bill O'Neil
Top achievements
Rank 1
answered on 07 Jul 2009, 02:17 PM
I'm getting the same "-1" in ColumnCreated - was this ever solved?
0
Iana Tsolova
Telerik team
answered on 08 Jul 2009, 08:48 AM
Hello Bill,

It seems it is to early to get the OrderIndex of a column on ColumnCreated event. You can try accessing it on grid PreRender event as in the attached sample.

All the best,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Darren
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Darren
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Iana Tsolova
Telerik team
Bill O'Neil
Top achievements
Rank 1
Share this question
or