Column Reorder in code

4 posts, 0 answers
  1. fgalarraga
    fgalarraga avatar
    18 posts
    Member since:
    May 2007

    Posted 20 Aug 2007 Link to this post

    How do you go about reordering the columns programatically?

    Thank you,
  2. Dwight
    Dwight avatar
    475 posts

    Posted 21 Aug 2007 Link to this post


    you can reorder columns by using the Columns collection in the grid template:
    radGridView1.MasterGridViewTemplate.Columns.Move(1, 2); 
    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.

    (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).

    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Karen Mattox
    Karen Mattox avatar
    7 posts
    Member since:
    Oct 2008

    Posted 15 May 2009 Link to this post

    This does not seem to work for child columns in a hierarchy. Is there a workaround for this?
  4. Nikolay
    Nikolay avatar
    1805 posts

    Posted 16 May 2009 Link to this post

    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,
    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.
Back to Top