Reordering Radgridview columns via 2 buttons at runtime

3 posts, 1 answers
  1. George C.
    George C. avatar
    29 posts
    Member since:
    Sep 2018

    Posted 25 Dec 2019 Link to this post

    Greetings,

    I know If i want to reorder Radgridview columns, I should use : Radgridview1.Columns.Move(lastIndex , Newindex)

    But I need to reorder columns at runtime and save the changes for the next run.

    So I can use 2 buttons : MoveForward , MoveBackward.

    And I can define 2 integer values in My.settings : LastIndex, NewIndex. (every column has these 2 integer values in my.settings)

    plus, I need to have a combo box to select the current column.

    As the Move function requires both the current index and desired index , it makes it a bit complicated with the combo Box and buttons. Because when I select and move a column no matter forward or backward (when combo box value is 1 , means the first column is out target to move), the current index should be updated with the desired index. For Example :

    Column 1 is in index 0. Now I want to reorder in order to place it in Index 1. So :

    I select value "1" in combo box, and then

    With Radgridview1

    .columns.move(combobox.text , combobox.text + 1)

    End with

     

    So what happens next ? If I'm about to move it 1 more index forward, then the above code should be ? How can I save latest changes in My.settings (the integer values we defined from the beginning)

     

    What is your approach ?

     

    Thanks for your attention.


  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 25 Dec 2019 Link to this post

    Hello, George,     

      

    I would like to note that RadGridView allows columns reordering by drag and drop behavior which I believe would be much more convenient for you. The user has just to drag the desired column's header at the desired position among the other headers and drop it there. In the RadGridView control, the AllowColumnReorder property value determines whether users can move columns to different positions. Additional information is available in the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/columns/reordering-columns

    You can also preserve the current columns order and restore it later when running the application on the next day for example. For this purpose you can use the default save/load layout that RadGridView offers: https://docs.telerik.com/devtools/winforms/controls/gridview/save-and-load-layout/save-and-load-layout

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Happy Holidays

     

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. George C.
    George C. avatar
    29 posts
    Member since:
    Sep 2018

    Posted 25 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Yes, I was aware of reordering by drag and drop behavior , but I didn't know about saving and loading layout feature. Thanks
Back to Top