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

Reorder rows in the RadGridView

3 Answers 264 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Artsiom Sinitski
Top achievements
Rank 1
Artsiom Sinitski asked on 06 Jul 2009, 08:22 PM
I and my partner are trying to figure out how to move current row (the highlighted one) in the RadGridView by pressing "Up" or "Down" buttons on our form. Is there a way of doing it ?


3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 07 Jul 2009, 11:11 AM
Hi Artsiom Sinitski,

By default, the Up and Down buttons do change the current item - the current item is indicated by a triangle shown in the indication (leftmost) column of RadGridView.

Are you getting a different behavior?

Kind regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Artsiom Sinitski
Top achievements
Rank 1
answered on 07 Jul 2009, 02:27 PM
Sorry, we did not make ourselves clear enough. We need to switch the position of the entire selected row with the row above/below it by pressing custom "Up" or "Down" buttons on the form. For example:


Before hitting "Up":
      1      2      3      4
      5      6      7      8
      9      10    11    12      
<= Selected Row

After Hitting "Up":
      1      2      3      4
      9      10    11    12       <= Selected Row
      5      6      7      8
0
Milan
Telerik team
answered on 13 Jul 2009, 05:58 AM
Hello Artsiom Sinitski,

That can be achieved with a little bit of code. I have prepared an application that demonstrates how this can be done.

First you have to take care of the default logic that is executed when key is pressed - by default when the user uses the arrow keys the current and selected items are changed. To change that you will have to create a custom control that inherits form GridViewItemsControl and override the OnKeyDown method. Once you do that the grid will not execute any action when the arrow keys are pressed.

The next thing to do is to subscribe to the KeyDown event of RadGridView and execute your custom logic when the event is raised. When the event is fired you remove the selected item from the data source and reinsert it at its new position. You have to use ObservableCollection as ItemsSource so that the grid can refresh its contents when data items change places.

Hope this works.

Kind regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Artsiom Sinitski
Top achievements
Rank 1
Answers by
Milan
Telerik team
Artsiom Sinitski
Top achievements
Rank 1
Share this question
or