C# datagridview只允许输入数字

2021/8/3 20:07:43

本文主要是介绍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;
   }
}

 



这篇关于C# datagridview只允许输入数字的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程