C# datagridview只允许输入数字

private void dgvData_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
  if (this.dgvData.CurrentCell.ColumnIndex == 3)
    {
      e.Control.KeyPress += new KeyPressEventHandler(TextBoxDec_KeyPress) ;
    }
}
private void TextBoxDec_KeyPress(object sender, KeyPressEventArgs e)
{
  if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != '.')
   {
     e.Handled = true;
   }
}

 

posted @ 2021-08-03 18:50  Cmale  阅读(507)  评论(0编辑  收藏  举报