KeyDown event - how to easily know if the key pressed is numeric?

后端 未结 8 1895
天命终不由人
天命终不由人 2020-12-19 03:00

I am currently handling the KeyDown event of a DataGridView control. One of the columns is filled by calculated values and I want the user to be able to override the cell va

8条回答
  •  半阙折子戏
    2020-12-19 03:31

    Try

    if ((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) ||
        (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9) ||
        e.KeyCode == Keys.Decimal)
    {
        // Edit mode
    }
    

提交回复
热议问题