Results 1 to 2 of 2

Thread: [RESOLVED] DataGridView - Getting cursor into textbox of the first cell in the row just created

  1. #1

    Thread Starter
    Addicted Member thetimmer's Avatar
    Join Date
    Jan 2014
    Location
    Plano, Texas
    Posts
    243

    Resolved [RESOLVED] DataGridView - Getting cursor into textbox of the first cell in the row just created

    At this point my code is starting to look... verbose. All I am trying to do is get my cursor into the text box in the first cell of the new DataGridView row I have created.

    My symptom is, although the correct Cell gets selected, if I start typing, the values get added to the Cell I just left... hope that's clear.

    Code:
    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
            Select Case keyData
                Case Keys.Down, Keys.Insert, Keys.Enter, Keys.Right
    
                    Dim iRI As Integer = Me.dgBooksToAdd.Rows.GetLastRow(DataGridViewElementStates.None)
                    If Me.dgBooksToAdd.Rows(iRI).Selected OrElse Me.dgBooksToAdd.Rows(iRI).Cells(0).Selected OrElse Me.dgBooksToAdd.Rows(iRI).Cells(1).Selected Then
                        If Me.dgBooksToAdd.Rows(iRI).Cells(0).Value <> String.Empty OrElse Me.dgBooksToAdd.Rows(iRI).Cells(1).Value <> String.Empty Then
                            Me.dgBooksToAdd.EndEdit()
                            Dim NewRI As Integer = Me.dgBooksToAdd.Rows.Add()
                            Me.dgBooksToAdd.Rows(Me.dgBooksToAdd.CurrentRow.Index + 1).Cells(0).Selected = True
                            Me.dgBooksToAdd.BeginEdit(False)
                            CType(Me.dgBooksToAdd.EditingControl, TextBox).Select(0, 1)
                        Else
                            Return MyBase.ProcessCmdKey(msg, keyData)
                        End If
                    End If
    
                Case Else
                    Return MyBase.ProcessCmdKey(msg, keyData)
            End Select
            Return True
        End Function
    _____________
    Tim

    If anyone's answer has helped you, please show your appreciation by rating that answer.
    When you get a solution to your issue remember to mark the thread Resolved.


    reference links

  2. #2

    Thread Starter
    Addicted Member thetimmer's Avatar
    Join Date
    Jan 2014
    Location
    Plano, Texas
    Posts
    243

    Re: DataGridView - Getting cursor into textbox of the first cell in the row just crea

    Never mind
    Found an older post that pointed out my very rookie mistake of not setting CurrentCell.

    Thank you jmcilhinney
    _____________
    Tim

    If anyone's answer has helped you, please show your appreciation by rating that answer.
    When you get a solution to your issue remember to mark the thread Resolved.


    reference links

Tags for this Thread

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