Matheus Bertolino Matheus Bertolino - 4 years ago 91
Vb.net Question

TAB click moves to next datagridview cell but cursor does not appear

I have a DataGridView into a Windows Form, and when I press right-arrow key, the cursor appears on the next cell. But when I press TAB, the selection changes but the cursor does not appear on the next cell, and what I really want is to make this cursor appear somehow.
I think that would be a solution doing TAB to emulate a Right-Arrow click when the user clicks TAB in some of the ComboBox/TextBox cells.
Some of the Subs I actually have in my Windows Form code:

Private Sub DataGridView1_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
sender.BeginEdit(True)
End Sub

Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
sender.BeginEdit(True)
End Sub

Private Sub DataGridView1EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If IsComboBoxCell(DataGridView1.CurrentCell) Then
Dim cb As ComboBox = TryCast(e.Control, ComboBox)
If cb IsNot Nothing Then
cb.DropDownStyle = ComboBoxStyle.DropDown
cb.DropDownHeight = 200
cb.AutoCompleteSource = Windows.Forms.AutoCompleteSource.ListItems
cb.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend
RemoveHandler cb.Validated, AddressOf cb_Validated
AddHandler cb.Validated, AddressOf cb_Validated
End If
End If
End Sub

Private Sub cb_Validated(sender As Object, e As EventArgs)
Dim selectedItem = CType(sender, ComboBox).SelectedItem
Dim col = CType(DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex), DataGridViewComboBoxColumn)
If String.IsNullOrEmpty(col.ValueMember) Then
DataGridView1.CurrentCell.Value = selectedItem

End If
End Sub


It works fine for Enter but does not work for TAB.
Is it possible to be done? The User press TAB but it fires like Right Arrow, or some other solution?

Answer Source

Check if your "StandardTab" property is not set to "true"

If it doesn't work (I don't know why) try handling keyup

 private void Data_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Tab)
            SendKeys.Send("{RIGHT}");
    }

sory for c# code but I guess you will easily write it in vb

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download