This is a migrated thread and some comments may be shown as answers.
Column Reorder in code
3 Answers 147 Views
This is a migrated thread and some comments may be shown as answers.
fgalarraga
Top achievements
Rank 1
fgalarraga asked on 20 Aug 2007, 05:08 PM
How do you go about reordering the columns programatically?

Thank you,
Frank

3 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 21 Aug 2007, 02:10 PM
Frank,

you can reorder columns by using the Columns collection in the grid template:
 
radGridView1.MasterGridViewTemplate.Columns.Move(1, 2); 
 
or
 
GridViewColumn col1 = radGridView1.MasterGridViewTemplate.Columns[...]; 
GridViewColumn col2 = radGridView1.MasterGridViewTemplate.Columns[...]; 
 
radGridView1.MasterGridViewTemplate.Columns.Move(col1, col2, InsertPosition.Before); 

In the first example you will place the column with index 1 at position 2. Note that indexing starts from 0 and both indexes should be of valid columns.

The second demonstrates how to move columns when you have column references. It moves col1 before col2.

Note: The first example correctly places the column at the target index, while the second one takes care for correctly placing the first column relative to the second. Both columns can be reordered, ie. the indexes may not be the same.

Example:
(numbers are used for column names for easier comprehension. colX references the column at position X. Initial columns ordering: 1  2  3  4  5  6  7).

Here is a table that presents the final ordering: 
 
Values for X and Y

2, 5

5, 2

 Move(X, Y) 1 3 4 5 2 6 7 1 5 2 3 4 6 7
 Move(colX, colY, InsertPosition.Before) 1 3 4 2 5 6 7 1 5 2 3 4 6 7
 Move(colX, colY, InsertPosition.After) 1 3 4 5 2 6 7 1 2 5 3 4 6 7

As you can see, the Move(X, Y) method always guarantees that column X will be at position Y after the move, while Move(colX, colY, ...) will always guarantee that colX will be before/after colY (depending on the third parameter).

 
Regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Karen Mattox
Top achievements
Rank 1
answered on 15 May 2009, 09:21 PM
This does not seem to work for child columns in a hierarchy. Is there a workaround for this?
0
Nikolay
Telerik team
answered on 16 May 2009, 12:00 PM
Hello Karen Mattox,

Could you be more specific about the issue that you are experiencing in hierarchy mode? I tested the Move method in hierarchy mode and found an issue with this method when there are no child views opened. I am sending the sample application which I used for my tests. Are there any other issues with Move that you can report?

Regarding the issue that I reproduced, we will address it in one of our next releases. Unfortunately, I cannot provide you with a workaround for the time being.

I am updating your Telerik points for the report. If you have additional questions, feel free to contact me.

All the best,
Nikolay
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.
Asked by
fgalarraga
Top achievements
Rank 1
Answers by
Dwight
Telerik team
Karen Mattox
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or