簡體   English   中英

TAB單擊移動到下一個datagridview單元格,但沒有出現光標

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

我將DataGridView放入Windows窗體,然后按右箭頭鍵,光標出現在下一個單元格上。 但是,當我按TAB鍵時,選擇發生了變化,但是光標沒有出現在下一個單元格上,而我真正想要的是使該光標以某種方式出現。 我認為這是一種在用戶單擊某些ComboBox / TextBox單元格中的TAB時模擬TAB來模擬右鍵單擊的解決方案。 我在Windows窗體代碼中實際擁有的一些Subs:

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”

如果不起作用(我不知道為什么),請嘗試處理鍵盤

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

急於C#代碼,但我想您會很容易在vb中編寫它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM