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
close icon

Moving rows

Hi, I am using GridDataBoundGrid. How can i move row or rows in the grid from 1 position to other. i tried using MoveRange() function but rows are not moved. Can you suggest something on this Regards, Pratiksha

8 Replies

AD Administrator Syncfusion Team February 2, 2005 03:15 AM UTC

Hi Pratiksha You''ll find a description and sample at http://www.syncfusion.com/Support/article.aspx?id=10379 Regards Thomas


AD Administrator Syncfusion Team February 2, 2005 04:04 AM UTC

In this Swap function swaps just 2 rows. If i have to move say 3 rows to new position.how can that be achieved >Hi Pratiksha > >You''ll find a description and sample at http://www.syncfusion.com/Support/article.aspx?id=10379 > >Regards >Thomas >


AD Administrator Syncfusion Team February 2, 2005 01:58 PM UTC

Hi Pratiksha You want to select more the one row and move them to a new position? Therefore you have to get the selected rows and the underlying DataRows. In a GDBG, is is the only way to use a helper column which has the sort information. The rows represent the DataSource, if you want to change the order in this view you have to maintain the extra column with an index. Regards Thomas


AD Administrator Syncfusion Team February 4, 2005 01:20 AM UTC

Hi, I am not getting exactly how it will be. Can you please share any code snippet for this. Regards Pratiksha >Hi Pratiksha > >You want to select more the one row and move them to a new position? Therefore you have to get the selected rows and the underlying DataRows. In a GDBG, is is the only way to use a helper column which has the sort information. The rows represent the DataSource, if you want to change the order in this view you have to maintain the extra column with an index. > >Regards >Thomas


AD Administrator Syncfusion Team February 4, 2005 07:00 PM UTC

Hi Pratiksha That''s the way how I get the selected rows. GridRangeInfoList ranges = null; CurrencyManager cm = (CurrencyManager) this.BindingContext[this.DataSource, this.DataMember]; ArrayList dataRows = new ArrayList(); //list of rows if( this.grid.Model.Selections.Ranges.ActiveRange.IsRows ) { ranges = this.grid.Selections.GetSelectedRows( true, false ); foreach(GridRangeInfo range in ranges) { int bottom = range.Bottom; for(int i = range.Top; i <= bottom; ++i) { int pos = this.grid.Binder.RowIndexToListManagerPosition(i); if( pos > -1 ) { if( cm.Count > 0 && pos < cm.Count ) { if( cm.List[pos] is DataRowView ) { dataRows.Add(((DataRowView)cm.List[pos]).Row); } } } } } } The rest should be easy for you to get the rows in the correct order. Regards Thomas >Hi, >I am not getting exactly how it will be. >Can you please share any code snippet for this. > >Regards >Pratiksha > >>Hi Pratiksha >> >>You want to select more the one row and move them to a new position? Therefore you have to get the selected rows and the underlying DataRows. In a GDBG, is is the only way to use a helper column which has the sort information. The rows represent the DataSource, if you want to change the order in this view you have to maintain the extra column with an index. >> >>Regards >>Thomas


AD Administrator Syncfusion Team February 4, 2005 07:02 PM UTC

The line should be: CurrencyManager cm = (CurrencyManager) this.BindingContext[this.grid.DataSource, this.grid.DataMember]; >Hi Pratiksha > >That''s the way how I get the selected rows. > > > GridRangeInfoList ranges = null; > CurrencyManager cm = (CurrencyManager) this.BindingContext[this.DataSource, this.DataMember]; > ArrayList dataRows = new ArrayList(); //list of rows > > if( this.grid.Model.Selections.Ranges.ActiveRange.IsRows ) > { > ranges = this.grid.Selections.GetSelectedRows( true, false ); > > foreach(GridRangeInfo range in ranges) > { > int bottom = range.Bottom; > for(int i = range.Top; i <= bottom; ++i) > { > int pos = this.grid.Binder.RowIndexToListManagerPosition(i); > if( pos > -1 ) > { > if( cm.Count > 0 && pos < cm.Count ) > { > if( cm.List[pos] is DataRowView ) > { > dataRows.Add(((DataRowView)cm.List[pos]).Row); > } > } > } > } > } > } > > >The rest should be easy for you to get the rows in the correct order. > >Regards >Thomas > >>Hi, >>I am not getting exactly how it will be. >>Can you please share any code snippet for this. >> >>Regards >>Pratiksha >> >>>Hi Pratiksha >>> >>>You want to select more the one row and move them to a new position? Therefore you have to get the selected rows and the underlying DataRows. In a GDBG, is is the only way to use a helper column which has the sort information. The rows represent the DataSource, if you want to change the order in this view you have to maintain the extra column with an index. >>> >>>Regards >>>Thomas


AD Administrator Syncfusion Team February 8, 2005 09:44 AM UTC

Hi, Code snippet u shared was for gettng the selected rows in teh grid. Here i dont want to swap the rows but just move the rows lets say 1 2 3 4 5 rows i want to move rows 2 and 3 after 4 so order of rows display will be 1,4,2,3,5 with the sory key it can just swap the 2 rows. >The line should be: >CurrencyManager cm = (CurrencyManager) this.BindingContext[this.grid.DataSource, this.grid.DataMember]; > >>Hi Pratiksha >> >>That''s the way how I get the selected rows. >> >> >> GridRangeInfoList ranges = null; >> CurrencyManager cm = (CurrencyManager) this.BindingContext[this.DataSource, this.DataMember]; >> ArrayList dataRows = new ArrayList(); //list of rows >> >> if( this.grid.Model.Selections.Ranges.ActiveRange.IsRows ) >> { >> ranges = this.grid.Selections.GetSelectedRows( true, false ); >> >> foreach(GridRangeInfo range in ranges) >> { >> int bottom = range.Bottom; >> for(int i = range.Top; i <= bottom; ++i) >> { >> int pos = this.grid.Binder.RowIndexToListManagerPosition(i); >> if( pos > -1 ) >> { >> if( cm.Count > 0 && pos < cm.Count ) >> { >> if( cm.List[pos] is DataRowView ) >> { >> dataRows.Add(((DataRowView)cm.List[pos]).Row); >> } >> } >> } >> } >> } >> } >> >> >>The rest should be easy for you to get the rows in the correct order. >> >>Regards >>Thomas >> >>>Hi, >>>I am not getting exactly how it will be. >>>Can you please share any code snippet for this. >>> >>>Regards >>>Pratiksha >>> >>>>Hi Pratiksha >>>> >>>>You want to select more the one row and move them to a new position? Therefore you have to get the selected rows and the underlying DataRows. In a GDBG, is is the only way to use a helper column which has the sort information. The rows represent the DataSource, if you want to change the order in this view you have to maintain the extra column with an index. >>>> >>>>Regards >>>>Thomas


AD Administrator Syncfusion Team February 8, 2005 10:30 AM UTC

You cannot easily move rows in a GridDataboundGrid bound to a datatable. The reason is that you cannot easily move rows in a (editable, sortable) datatable. And since the grid just reflects the exact contents of the DataSource (or its associated DataView), it is the contrnts of the DataSource that you need to shuffle and this is not doable in general. You can add a column to your DataTable, and initialize it to 1,2,3,4 etc. Then always display your grid sorted on this hidden column. Then when you want to move rows, you can just swap the values in this hidden column to make them display in a different order. Here is a forum thread that discusses this work-around. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=16227

Loader.
Live Chat Icon For mobile
Up arrow icon