How to disable reordering specific column?

7 posts, 1 answers
  1. Raymond
    Raymond avatar
    134 posts
    Member since:
    Jul 2010

    Posted 14 Jan 2011 Link to this post

    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

  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Jan 2011 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Jan 2011 Link to this post

    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
  5. Raymond
    Raymond avatar
    134 posts
    Member since:
    Jul 2010

    Posted 14 Jan 2011 Link to this post

    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.
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Jan 2011 Link to this post

    Yep, that would do it. Glad I could help
    All the best
    Richard
  7. Shashikant
    Shashikant avatar
    1 posts
    Member since:
    Dec 2012

    Posted 22 Jan 2013 Link to this post

    How to achieve same behaviour in javascript.
  8. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 22 Jan 2013 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready