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


Reply With Quote
