chris_asa
Active member
I have the following code to move a line up in the ....datagridview (datatable, (database)):
CurrentCase object contains a disconnected datatable .Lines
CurrentCase.Lines.Columns("LineSort") is there to persist the desired line-sequence at the db
dgvLines is a datagridview <-- bindingsource <-- datatable (CurrentCase.Lines)
IsDirty is a Private form Boolean that eventually triggers an update to the DB in code elsewhere.
Is there a neater solution than u, d ?
Is dgvLines.Sort the best way through this ?
regards Chris
VB.NET:
If Not Me.dgvLines.CurrentRow Is Nothing Then
Dim i As Integer = Me.dgvLines.CurrentRow.Index
If i > 0 Then
With CurrentCase.Lines
Dim u As Integer = .Rows(i - 1).Item("LineSort")
Dim d As Integer = .Rows(i).Item("LineSort")
.Rows(i - 1).Item("LineSort") = d
.Rows(i).Item("LineSort") = u
.AcceptChanges()
End With
Me.dgvLines.Sort(Me.dgvLines.Columns("LineSort"), System.ComponentModel.ListSortDirection.Ascending)
IsDirty = True
Me.dgvLines.Rows(i - 1).Selected = True
End If
End If
CurrentCase object contains a disconnected datatable .Lines
CurrentCase.Lines.Columns("LineSort") is there to persist the desired line-sequence at the db
dgvLines is a datagridview <-- bindingsource <-- datatable (CurrentCase.Lines)
IsDirty is a Private form Boolean that eventually triggers an update to the DB in code elsewhere.
Is there a neater solution than u, d ?
Is dgvLines.Sort the best way through this ?
regards Chris