Bypass read only cells in DataGridView when pressing TAB key

前端 未结 8 719
粉色の甜心
粉色の甜心 2020-12-31 18:07

Can anyone show me some code of how I could bypass read only cells in DatagridView when pressing TAB key?

8条回答
  •  半阙折子戏
    2020-12-31 18:15

    When the cell is in edit mode, and you want to listen to keystroke events, you might try handling the DataGridView's EditingControlShowing event...

    Private Sub myDvGrid_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles myDvGrid.EditingControlShowing
        Dim c As DataGridViewTextBoxEditingControl = DirectCast(e.Control, DataGridViewTextBoxEditingControl)
    
        RemoveHandler c.PreviewKeyDown, AddressOf edtctrlOn_PreviewKeyDown
        RemoveHandler c.TextChanged, AddressOf edtctrlOn_TextChanged
    
        AddHandler c.TextChanged, AddressOf edtctrlOn_TextChanged
        AddHandler c.PreviewKeyDown, AddressOf edtctrlOn_PreviewKeyDown
    
    End Sub
    

    Then, in the edtctrlOn_PreviewKeyDown event, you can bubble the arguments over to the original datagrid's PreviewKeyDown event handler.

提交回复
热议问题