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

HowTo: Prevent Recorder of a Column

0 Answers 11 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jorge Gonzalez
Top achievements
Rank 1
Jorge Gonzalez asked on 15 Jan 2010, 05:40 PM
Hello,
     I finally figured out how to prevent a user from re-ordering the first column in my grid. 

Here's how I did it:

In the DataLoaded event of my grid I typed in this line (for the first column in grid):
((Telerik.Windows.Controls.GridView.GridViewDataControl)(sender)).Columns[0].IsReorderable = false;

Note. What's kind of strange about this command is that I can't reorder the first column but I can move other columns in front of it.

In the  ColumnReordered event of the grid I typed in the following lines of code:

private void ColumnReordered(object sender, GridViewColumnEventArgs e)
        {
            if (e.Column.DisplayIndex == 0)
                for (int i = 1; i < gridname.Columns.Count ; i++)
                    if (e.Column.Header == gridname.Columns[i].Header)
                        e.Column.DisplayIndex = i;
        }

Note. e.Column.DisplayIndex indicates where the user tried to move the column to.

If the user attempts to move a column to the position of the first column, the code above will search for the original location of the column being moved and set e.Column.DisplayIndex  back to it's original value.  Essentially I am moving the column back to its original location.

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Jorge Gonzalez
Top achievements
Rank 1
Share this question
or