Results 1 to 3 of 3

Thread: DataGridView move and select row issue (Resolved)

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Question 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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    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
  •  



Click Here to Expand Forum to Full Width