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. Image for the cookie policy date

Moving rows up & down in the grid

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?

5 Replies

AD Administrator Syncfusion Team May 12, 2003 02:25 PM UTC

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).


SH Shulin He August 26, 2003 07:28 PM UTC

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). > >


AD Administrator Syncfusion Team August 27, 2003 07:44 PM UTC

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.


AD Administrator Syncfusion Team November 8, 2003 11:05 PM UTC

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


AD Administrator Syncfusion Team November 9, 2003 07:34 AM UTC

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.

Loader.
Live Chat Icon For mobile
Up arrow icon