I would llike to use drag drop to reorder the students. (see sample Jpg file attached)
The studentNo field is the same as the row index plus 1, and the fill query for the DataGridView is
sorted by StudentNo, so the code just has to change the studentNo appropriately.
The best I can come up with so far is a button which lifts the selected row by one row.
(Similarly I can add a down button to do the reverse)
Repeated clickng of this button achieves the desired result but is not very user friendly.
Also I think the code (atached) is messy.
For drag and drop, I was looking for a mouse down event and Mouse up event to tell me the "from row" and the "to row" but the CurrentCell.RowIndex.Value
is always a value behind
because the selected row does not change until after the mouse up event occurs.
Any ideas would be appreciated.
Private Sub ButMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButMoveUp.Click
Dim JPCurrentRow As Int16 = CShort(EntriesDGV.CurrentRow.Index)
If JPCurrentRow > 0 Then
'Get Parameter in preparation for re-fill
Dim ParmExamCode As String
ParmExamCode = CStr(AvailExamsDGV.Item("AeDgvExamCode", AvailExamsDGV.CurrentCell.RowIndex).Value)
' Swap order one row
Dim JPCurrentRowID As Int32 = CInt(EntriesDGV.Item("EntryID", JPCurrentRow).Value)
Dim JPToRowID As Int32 = CInt(EntriesDGV.Item("EntryID", JPCurrentRow - 1).Value)
Me.EntriesTableAdapter.QryUpdateStudentNo(JPCurrentRow + CShort(1), JPToRowID)
'EntriesDGV.Item("StudentNo", JPToRow).Value = JPToRow - 1
'EntriesDGV.Item("StudentNo", JPToRow - 1).Value = JPToRow
'Re-fill DataGrid view
MsgBox("Already on first Row")