编程语言
首页 > 编程语言> > C# datagridview只允许输入数字

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;
   }
}

 

标签:object,C#,KeyChar,TextBoxDec,private,datagridview,void,KeyPress,输入
来源: https://www.cnblogs.com/Fpack/p/15095670.html