I think I need to use a currency manager for this job but I'm not sure
how to make it work.
Using a dataview as the datasource for a datagrid.
Sorting not allowed per the tablestyles.
There is a column in the table which is not displayed which controls
the display order. To move a row (or group of rows) in the table
select the rows to move and click the appropriate button next to the datagrid.
One button shifts rows up. A second button shifts rows down.
That much works fine.
After changing the integer values in the displayorder column I reset the
dataview.sort = "displayorder" and the selected rows now appear in
the proper order shifted one row from their previous position.
After shifting the rows I reselect the rows.
My problem is that if I then click the shift button a second time
only the first row selected is shifted and after the shift only that
one shifted row is selected.
Any suggestions?
My shift up Code:
Private Sub cbShiftUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cbShiftUp.Click
Dim dvShift As DataView = dgFleetList.DataSource
Dim drvRow As DataRowView
Dim drvSwap As DataRowView
Dim iPUR As Integer
Dim iSwap As Integer
Dim iR As Integer
Dim iSel As Integer
Dim alChosen As New ArrayList()
'Exit if shifting up is trivial
If dvShift.Count < 2 Then Exit Sub
If dgFleetList.IsSelected(0) Then Exit Sub
'Initialize iPUR (Previous Unselected Row)
iPUR = 0
'Empty the Chosen Row Arraylist
alChosen.Clear()
'Loop through rows
For iR = 1 To dvShift.Count - 1
If dgFleetList.IsSelected(iR) Then
'Swap display position values with iPUR
drvRow = dvShift.Item(iR)
iSwap = drvRow.Item("DisplayOrder")
drvSwap = dvShift.Item(iPUR)
drvRow.Item("DisplayOrder") = drvSwap.Item("DisplayOrder")
alChosen.Add(iR - 1)
drvSwap.Item("DisplayOrder") = iSwap
Else
'Reset iPUR
iPUR = iR
End If
Next
dvShift.Sort = "DisplayOrder"
'Reselect chosen rows
For iR = 0 To alChosen.Count - 1
dgFleetList.Select(alChosen(iR))
Next
End Sub