DataGridView move and select row issue (Resolved)
Hello,
I am trying to move a row in a datagridview and then select that row in case they want to move it up or down again.
I have the code to move the row and then select the row here:
Dim curRow As Integer = Me.dgvByTestCase.CurrentCell.RowIndex
Dim myRow As DataGridViewRow = Me.dgvByTestCase.CurrentRow
Me.dgvByTestCase.Rows.Remove(myRow)
Me.dgvByTestCase.Rows.Insert(curRow - 1, myRow)
Me.dgvByTestCase.ClearSelection()
Me.dgvByTestCase.Rows(curRow - 1).Selected = True
Now this works but the issue is the row that I selected shows as being highlighted but it's not really selected.
The row may be highlighted but the little black arrow is now two rows below the highlighted one and if I click move up again it moves the row that has the black arrow and not the highlighted row.
Thank you so much in advance for any assistance you may have.
Mythos
Re: DataGridView move and select row issue
instead of selecting the row how you are, try setting the currentcell to the new row, column 0
Re: DataGridView move and select row issue
okay I just had to add this line of code and it fixed the issue
Me.dgvByTestCase.Rows(curRow - 1).Cells(1).Selected = True
so the final code looks like this:
Dim curRow As Integer = Me.dgvByTestCase.CurrentCell.RowIndex
Dim myRow As DataGridViewRow = Me.dgvByTestCase.CurrentRow
Me.dgvByTestCase.Rows.Remove(myRow)
Me.dgvByTestCase.Rows.Insert(curRow - 1, myRow)
Me.dgvByTestCase.ClearSelection()
Me.dgvByTestCase.Rows(curRow - 1).Cells(1).Selected = True
Me.dgvByTestCase.Rows(curRow - 1).Selected = True
Thanks all again