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

Reordering Radgridview columns via 2 buttons at runtime

2 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George C.
Top achievements
Rank 2
Iron
Veteran
George C. asked on 25 Dec 2019, 11:50 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Dec 2019, 12:02 PM

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.
0
George C.
Top achievements
Rank 2
Iron
Veteran
answered on 25 Dec 2019, 01:04 PM
Yes, I was aware of reordering by drag and drop behavior , but I didn't know about saving and loading layout feature. Thanks
Tags
GridView
Asked by
George C.
Top achievements
Rank 2
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
George C.
Top achievements
Rank 2
Iron
Veteran
Share this question
or