|
-
Nov 3rd, 2010, 12:13 PM
#1
Thread Starter
Member
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
Last edited by Mythos44; Nov 3rd, 2010 at 12:44 PM.
Reason: Resolved
-
Nov 3rd, 2010, 12:24 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 3rd, 2010, 12:43 PM
#3
Thread Starter
Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|