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

Column reordering by UniqueName not working

1 Answer 64 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jonathan Miller
Top achievements
Rank 1
Jonathan Miller asked on 10 Dec 2011, 06:35 PM
I am trying to reorder some columns in the GridView, based on their name. I have 25 columns, and they reorder, but not in the order they are suppose to. Can you give any insight why they are in the wrong order?


public static void ReorderColumns(this RadGridView gridView, params string[] columnNames)

        {

            for (int i = 0; i < columnNames.Length; i++)

            {

                string currentName = columnNames[i];

                GridViewDataColumn column = (GridViewDataColumn)gridView.Columns[currentName];

                int oldIndex = gridView.Columns.IndexOf(column);

                gridView.ReorderColumns(oldIndex, i);

            }

        }


1 Answer, 1 is accepted

Sort by
0
Jonathan Miller
Top achievements
Rank 1
answered on 12 Dec 2011, 03:34 PM
In case this helps anyone, here is how it was resolved.

 public static void ReorderColumns(this RadGridView gridView, params string[] columnNames)

        {

            for (int i = 0; i < columnNames.Length; i++)

            {

                string currentName = columnNames[i];

                GridViewDataColumn column = (GridViewDataColumn)gridView.Columns[currentName];

                int oldIndex = column.DisplayIndex;

                if (oldIndex < 0)

                {

                    oldIndex = gridView.Columns.IndexOf(column);

                }

                gridView.ReorderColumns(oldIndex, i);

            }

        }


Tags
GridView
Asked by
Jonathan Miller
Top achievements
Rank 1
Answers by
Jonathan Miller
Top achievements
Rank 1
Share this question
or