TAB 单击移动到下一个 datagridview 单元格但光标不出现
TAB click moves to next datagridview cell but cursor does not appear
我有一个 DataGridView 到 Windows 窗体,当我按右箭头键时,光标出现在下一个单元格上。但是当我按下 TAB 时,选择发生了变化,但光标没有出现在下一个单元格上,而我真正想要的是让这个光标以某种方式出现。
我认为这将是一个解决方案,当用户在某些 ComboBox/TextBox 单元格中单击 TAB 时,执行 TAB 以模拟右箭头单击。
我在 Windows 表格代码中实际拥有的一些潜艇:
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
它对 Enter 有效,但对 TAB 无效。
有可能完成吗?用户按 TAB 但它像向右箭头或其他解决方案一样触发?
检查您的 "StandardTab" 属性 是否未设置为 "true"
如果它不起作用(我不知道为什么)尝试处理 keyup
private void Data_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
SendKeys.Send("{RIGHT}");
}
对不起 C# 代码,但我想你会很容易地在 vb
中编写它
我有一个 DataGridView 到 Windows 窗体,当我按右箭头键时,光标出现在下一个单元格上。但是当我按下 TAB 时,选择发生了变化,但光标没有出现在下一个单元格上,而我真正想要的是让这个光标以某种方式出现。 我认为这将是一个解决方案,当用户在某些 ComboBox/TextBox 单元格中单击 TAB 时,执行 TAB 以模拟右箭头单击。 我在 Windows 表格代码中实际拥有的一些潜艇:
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
它对 Enter 有效,但对 TAB 无效。 有可能完成吗?用户按 TAB 但它像向右箭头或其他解决方案一样触发?
检查您的 "StandardTab" 属性 是否未设置为 "true"
如果它不起作用(我不知道为什么)尝试处理 keyup
private void Data_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
SendKeys.Send("{RIGHT}");
}
对不起 C# 代码,但我想你会很容易地在 vb
中编写它