We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Moving rows up & down in the grid

Thread ID:

Created:

Updated:

Platform:

Replies:

4419 May 12,2003 09:06 AM Nov 9,2003 02:34 AM Windows Forms 5
loading
Tags: GridControl
Loga
Asked On May 12, 2003 09:06 AM

In GridDataBoundGrid I just want to move the individual rows up and down with two command buttons placed outside the grid ,all in a group box.How to go with this?

Administrator [Syncfusion]
Replied On May 12, 2003 10:25 AM

In a GridDataBoundGrid, the grid just displays the rows as they are presented to it by the underlying datasource. So, if you want to move the position of the rows in the grid, currently you have to do so by moving them in the underlying datasource. Here is one way you can do it. This sample adds an additional column to the datatable that holds a sortKey that reflects where you want the row to be. You don't display this column (you can hide using GridBoundColumn for the columns you want to see, or you can just hide it in the grid as the sample does). When you initially set the DataSource to the grid, you sort the datatable on this column using its defaultview.sort property. Then when you want to move rows, all you have to do is to move the sortKey values and the rows will rearrange themselves (as they must maintain the sort order).

Shulin He
Replied On August 26, 2003 03:28 PM

Hi, Clay I used the method in your attachment to move rows up and down. It worked fine in the grid. But it was not updated in the DataSet or DataTable object because the data still had the same sequence after I saved and reloaded. I checked my code that I have called the AcceptChanges() method in the either the DataTable or the DataSet object. Could you show me another way of moving rows as you mentioned in your previous message? Sam > In a GridDataBoundGrid, the grid just displays the rows as they are presented to it by the underlying datasource. So, if you want to move the position of the rows in the grid, currently you have to do so by moving them in the underlying datasource. > > Here is one way you can do it. This sample adds an additional column to the datatable that holds a sortKey that reflects where you want the row to be. You don't display this column (you can hide using GridBoundColumn for the columns you want to see, or you can just hide it in the grid as the sample does). When you initially set the DataSource to the grid, you sort the datatable on this column using its defaultview.sort property. Then when you want to move rows, all you have to do is to move the sortKey values and the rows will rearrange themselves (as they must maintain the sort order). > >

Administrator [Syncfusion]
Replied On August 27, 2003 03:44 PM

If you want to move rows in a DataTable, then I think you will have to remove the row and insert a new one with the same data. Attached is the sample modified to actually reaarange the rows in the DataTable, and not just re-order their display in the grid.

Administrator [Syncfusion]
Replied On November 8, 2003 06:05 PM

Clay, I came across a similar scenario where I need to provide Insert row, Move Up, Move down feature for my grid. I got the move up/move down to work with "DisplayOrder" hidden column. I am not too keen on re arranging my rows in the data table. I tried to get the Insert Row to work. I added a row to the datatable, and tried to rest the display order of rows from current row to the last row in the grid. It is getting totally wacked up. Can you let me know how it can be done in your first sample. thanks, - Reddy

Administrator [Syncfusion]
Replied On November 9, 2003 02:34 AM

To use this technique, I think you will have to ripple the new row backup through the sorted view to where you want it inserted. Attached is a little sample. This solution does not scale well. If you a couple hundred rows in your view, it probably works OK. But if you have tens of thousands of rows, then inserting a rows near the top will be too time consuming. You might be able to speed this up by grabbing the current sortkeys in an array. Then just ripple through this array moving the sortkeys down. Then re-apply the sort keys to the DataTable. This way you might be able to avoid rippling the rows in teh view (which sorts things with each ripple.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;