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

How to disable reordering specific column?

6 Answers 303 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 14 Jan 2011, 11:51 AM

Hi

RadGridView has property AllowColumnReorder.

How can I disable reordering specific column?

 

In my case I don`t want let user move first column, all other columns can be reordered.

 

Regards

6 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 14 Jan 2011, 12:24 PM
Hi Raymond,

Hope you're well.
This should stop the first column being re-ordered
this.radGridView1.Columns.CollectionChanging += new NotifyCollectionChangingEventHandler(Columns_CollectionChanging);

private void Columns_CollectionChanging(Object sender, NotifyCollectionChangingEventArgs e)
{
    if (e.Action == NotifyCollectionChangedAction.Move)
    {
        if (e.OldStartingIndex == 0)
        {
            e.Cancel = true;
        }
    }
}

Hope that helps
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 14 Jan 2011, 02:39 PM
Hi again Raymond,

Actually, the below works better... the above would fail if you re-order one of the other columns to the 0 indexed position.
  this.radGridView1.Columns.CollectionChanged += new NotifyCollectionChangedEventHandler(Columns_CollectionChanged);
private void Columns_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   {
       if (this.radGridView1.Columns["Id"].Index != 0)
       {
           this.radGridView1.Columns.Move(this.radGridView1.Columns["Id"].Index, 0);
       }
   }

However, the limitation to this is that if you pin a different column to the left, then it will still replace the 0 indexed column.
Richard
0
Raymond
Top achievements
Rank 1
answered on 14 Jan 2011, 03:33 PM
I changed your code a little:

if (e.Action == NotifyCollectionChangedAction.Move)
{
    if ((e.OldStartingIndex == 0) || (e.NewStartingIndex == 0))
    {
        e.Cancel = true;
    }
}

and it works fine.

Thanks for help.
0
Richard Slade
Top achievements
Rank 2
answered on 14 Jan 2011, 03:35 PM
Yep, that would do it. Glad I could help
All the best
Richard
0
Shashikant
Top achievements
Rank 1
answered on 22 Jan 2013, 01:24 PM
How to achieve same behaviour in javascript.
0
Stefan
Telerik team
answered on 22 Jan 2013, 02:13 PM
Hello Shashikant,

Thank you for writing.

This forum concerns RadControls for WinForms, and your question seems to be unrelated to it. Please address it to the appropriate forums: RadGridView for ASP.NET AJAX.

Greetings,
Stefan
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Raymond
Top achievements
Rank 1
Shashikant
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or