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

[Solved] Moving Rows - Looking For Suggestions

1 Answer 113 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Scott
Top achievements
Rank 1
Scott asked on 20 Jul 2011, 12:38 AM

I’m currently using the GridView to show one to many rows – always containing two columns.  You can think of it as a name/value pair list.  The GridView does a nice job of showing all the data to the user.  However, my users have added a new requirement that I believe is beyond what the GridView can (or should) do.

My users want the ability to change the order of the rows one by one.  An example would be adding a third column that contains an up and down arrow.  If the user clicks the up arrow, the row would be moved into the front of the preceding row.  The user could then move the rows up and down and put them in any order they chose.  Of course, having slick animation during the moving of the rows would be a huge plus.

I’m guessing I won’t be able to use the GridView for this, but can anyone know where I should start with something like this?  We’ve all seen this behavior before, but I’ve never tried to implement it until now.

Thanks!

-Scott

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 20 Jul 2011, 03:47 PM
Hi Scott,

You may create a CellTemplate for a particular column, define a button inside and handle its Click event similar to:

private void UpButton_Click(object sender, RoutedEventArgs e)
        {
            IList items = this.clubsGrid.ItemsSource as IList;
 
            RadButton button = sender as RadButton;
            GridViewRow row = button.ParentOfType<GridViewRow>();
            if (row != null)
            {
                Club itemToMove = row.Item as Club;
                int currentIndex = this.clubsGrid.Items.IndexOf(itemToMove);
                if (currentIndex > 0)
                {
                    items.Remove(itemToMove);
                    items.Insert(currentIndex - 1, itemToMove);
                }
                else
                {
                    MessageBox.Show("The item cannot be moved up.");
                }
            }
        }

Still, I am sending you a sample project illustrating the suggested approach. Let me know whether it will suit your needs.
On the other hand, you may also run through our demo for additional reference on how you may reorder rows.
  Regards,
Maya
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
Scott
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or