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

Altering row index using default view

I have created a data bound grid sourced from a datatable and using a default view to sort the rows. I have an up and a down button to enable the user to select a row and move it up and down the grid by altering a sort order field. It works fine as long as I keep going in the same direction, up or down, but gets the sort order wrong if I switch directions without moving off the row. The sort order is column 7 in the grid so I increment/decrement this field in the current row and increment/decrement the field in the row above/below. Anything obviously wrong before I supply more details? The code is as follows: Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click ''move the selected row one place up the list Dim drEmployee1, drEmployee2 As dsEmployee.EmployeeRow Dim rowIndex, rowDatasource As Int32 Dim cc As GridCurrentCell rowIndex = gridEmployee.Binder.CurrentRowIndex If rowIndex > 1 Then gridEmployee.BeginUpdate() gridEmployee(rowIndex, 7).CellValue -= 1 gridEmployee(rowIndex - 1, 7).CellValue += 1 cc = gridEmployee.CurrentCell cc.MoveTo(rowIndex - 1, 0) gridEmployee.EndUpdate() End If End Sub Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click ''move the selected row one place down the list Dim drEmployee1, drEmployee2 As dsEmployee.EmployeeRow Dim rowIndex, rowDatasource As Int32 Dim cc As GridCurrentCell rowIndex = gridEmployee.Binder.CurrentRowIndex If rowIndex < gridEmployee.Model.RowCount - 1 Then gridEmployee.BeginUpdate() gridEmployee(rowIndex, 7).CellValue += 1 gridEmployee(rowIndex + 1, 7).CellValue -= 1 cc = gridEmployee.CurrentCell cc.MoveTo(rowIndex + 1, 0) gridEmployee.EndUpdate() End If End Sub

2 Replies

AD Administrator Syncfusion Team May 28, 2004 01:21 PM

To add detail (confusion) I can report that the problem occurs because the cell value of BOTH rows is altered by the second CellValue statement, but only after changing direction. So if I keep going up, for example, the CellValue statements work as expected, but if I click down once, then the first CellValue statement correctly increments column 7 of rowIndex but the second one appears to decrement column 7 of rowIndex+1 AND rowIndex.


AD Administrator Syncfusion Team May 28, 2004 02:26 PM

You might try calling gridEmployee.Binder.EndEdit after you change each value.

Loader.
Live Chat Icon For mobile
Up arrow icon