ousoonerjoe
Programmer
Using Vb.Net 2005
DataGridView with 3 columns.
With a great help from RiverGuy, the ListView item reordering was made quite simple and rather straight forward. When adjusting the same procedure to utilize an unbound DataGridView with 3 columns, it's not as pretty.
The results of the following delete the selected row, but inserts a blank line with only the default values 2 down from the selected row. The intent is to copy the selected row, insert it after the next row, delete the original selected row. Most of this process is working except the actual copying of the row. CurrentItem does get the row data from the .Clone call. It is given an .Index of -1. Not a problem since the index will be reassigned during the .Insert. The problem is the row data. When pushing the column data to a message box, it is there in the CurrentItem object, but does not seem to carry through on the .Insert.
Any assistance or guidance is appreciated.
--------------------------------------------------
Bluto: What? Over? Did you say "over"? Nothing is over until we decide it is! Was it over when the Germans bombed Pearl Harbor? No!
Otter: Germans?
Boon: Forget it, he's rolling.
--------------------------------------------------
DataGridView with 3 columns.
With a great help from RiverGuy, the ListView item reordering was made quite simple and rather straight forward. When adjusting the same procedure to utilize an unbound DataGridView with 3 columns, it's not as pretty.
The results of the following delete the selected row, but inserts a blank line with only the default values 2 down from the selected row. The intent is to copy the selected row, insert it after the next row, delete the original selected row. Most of this process is working except the actual copying of the row. CurrentItem does get the row data from the .Clone call. It is given an .Index of -1. Not a problem since the index will be reassigned during the .Insert. The problem is the row data. When pushing the column data to a message box, it is there in the CurrentItem object, but does not seem to carry through on the .Insert.
Any assistance or guidance is appreciated.
Code:
If dgJobStages.SelectedRows.Count > 0 Then
Dim CurrentPosition As Integer = dgJobStages.SelectedRows(0).Index
Dim PreviousPosition As Integer = IIf(CurrentPosition > 0, CurrentPosition - 1, CurrentPosition)
Dim NextPosition As Integer = IIf(CurrentPosition < dgJobStages.Rows.Count - 1, CurrentPosition + 2, CurrentPosition)
Dim CurrentItem As DataGridViewRow = dgJobStages.SelectedRows(0).Clone
Dim SelectedItem As DataGridViewRow = dgJobStages.SelectedRows(0)
dgJobStages.Rows.Insert(NextPosition, CurrentItem)
dgJobStages.Rows.Remove(SelectedItem)
CurrentItem.Selected = True
End If
--------------------------------------------------
Bluto: What? Over? Did you say "over"? Nothing is over until we decide it is! Was it over when the Germans bombed Pearl Harbor? No!
Otter: Germans?
Boon: Forget it, he's rolling.
--------------------------------------------------