C# datagridview 输入数字验证

 this.View.Dgv_storage.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(Dgv_storageEditingControlShowing);
  public void Dgv_storageEditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.CellStyle.Format == "N0" || e.CellStyle.Format == "N1")
            {
                Control control = new TextBox();
                control = (TextBox)e.Control;
                if (control.Name == "")
                {
                    control.KeyPress += new KeyPressEventHandler(Dgv_keypress);

                }
            }
        }
        public void Dgv_keypress(object sender, KeyPressEventArgs e)
        {
            if (((int)e.KeyChar >= 48 && (int)e.KeyChar <= 57) || e.KeyChar == 13 || e.KeyChar == 8 || e.KeyChar == 46)
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
                this.View.ShowTips("请输入数字");
            }

        }

你可能感兴趣的:(C# datagridview 输入数字验证)