DataGridView keydown event not working in C#

前端 未结 5 684
北恋
北恋 2020-11-28 11:02

DataGridView keydown event is not working when I am editing text inside a cell.

I am assigning shortcut Alt+S to save the data, it works when cell

5条回答
  •  孤街浪徒
    2020-11-28 11:07

    A simpler way I just tried out is as follows:

    1. Set the KeyPreview property of the Form to true.
    2. Instead of catching the KeyDown event on Grid, catch the KeyDown event on Form.

    Code as follows:

    Private Sub form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
    
       If grd.Focused Then
    
          'Do your work
    
       End If
    
    End Sub
    

提交回复
热议问题