Moves first 3 columns to end of columns collection

3 posts, 2 answers
  1. Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 20 Oct 2010 Link to this post

    I would like to move the first 3 columns in columns collection to end of the collection.
    If there were a total of 10 columns, then I want to move columns 1,2 and 3 so that they are columns 8,9,10.

    Thanks
    Sunil
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 21 Oct 2010 Link to this post

    Hello Sunil,

    In the current version, on DataBindingComplete event you can move the columns by using
    Columns.Move(oldIndex, newIndex)
    or
    Columns.Move(columnToMove, targetColumn, newIndex)

    And if i remember correctly in the older versions you could also set Columns[0].Index = index, or something very similar.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Sunil
    Sunil avatar
    230 posts
    Member since:
    Jan 2004

    Posted 22 Oct 2010 Link to this post

    I used the following code with success to move the first three columns of 'Changes', 'Save' and 'Cancel' to the end of existing columns collections. The end result is that the last 3 columns are now 'Changes', 'Save' and 'Cancel'  in the same physical order.

                if (this.Columns["Changes"].Index < 3)
               {
                   this.Columns.Move(this.Columns["Changes"].Index, this.Columns.Count-1);
               }
               if (this.Columns["Save"].Index <3)
               {
                   this.Columns.Move(this.Columns["Save"].Index, this.Columns.Count-1);
               }
               if (this.Columns["Cancel"].Index <3)
               {
                   this.Columns.Move(this.Columns["Cancel"].Index, this.Columns.Count-1);
               }
Back to Top