您的位置:首页 > 编程语言 > C#

C# datagridview 某列只能输入英文或数字

2013-10-25 11:42 218 查看
方法许多

正直表达式:"^[a-zA-Z0-9]+$"
这里不详细解答

自己用的方法是:

 private void datagridview1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs
e)

        {

            TextBox innerTextBox;

            if (e.Control is TextBox &&
datagridview1.CurrentCell.ColumnIndex==1) {

                innerTextBox = e.Control as TextBox;

                innerTextBox.KeyPress +=new KeyPressEventHandler(innerTextBox_KeyPress);

            }

        }

        private void innerTextBox_KeyPress(object sender, KeyPressEventArgs e) {

            if (e.KeyChar != 8 && !char.IsNumber(e.KeyChar) && !char.IsLower(e.KeyChar) && !char.IsUpper(e.KeyChar))

            {

                e.Handled = true;

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C#