搜索
首页 电子数码 手机/通讯 手机使用

怎么控制datagridview里的单元格输入格式只能输入手机号

全部回答

2019-01-02

0 0
    正则表达式可以,还有一种方法,就是判断:在datagridview的。keypress事件中判断是否是数字键(手机号一般是11位),不是数字键就禁掉例如:(这是vb2005的代码,不知道你用的是哪个,但程序代码意思基本相同,只是书写方式不一样,亲,相信你能懂)Public EditCell As DataGridViewTextBoxEditingControlPrivate Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System。
    Windows。Forms。DataGridViewEditingControlShowingEventArgs) Handles DataGridView1。EditingControlShowingEditCell = CType(e。
  Control, DataGridViewTextBoxEditingControl)EditCell。  SelectAll()AddHandler EditCell。KeyPress, AddressOf Cells_KeyPressEnd SubPrivate Sub Cells_KeyPress(ByVal sender As System。
  Object, ByVal e As KeyPressEventArgs)If e。  KeyChar > Chr(48) Or e。KeyChar Beep()Beep()e。
  KeyChar = Chr(0)End IfEnd Sub如果是C#,我这里给你一个:DataGridView中的单元格中只能输入数字的一种解决方法 :就是给DataGirdView添加CellParsing方法 private void dataGridView5_CellParsing(object sender, DataGridViewCellParsingEventArgs e) { DataGridView dgv = (DataGridView)sender; System。
    Text。RegularExpressions。Regex reg1 = new System。Text。RegularExpressions。Regex(@"^[-]?d [。
  ]?d*$"); if (!reg1。IsMatch(e。Value。ToString())) { MessageBox。  Show("对不起!必须是数字,请重新输入!"); e。
  Value = "0。00"; e。ParsingApplied = true; } }你可以试试,祝你成功!。

类似问题换一批

热点推荐

热度TOP

相关推荐
加载中...

热点搜索 换一换

电子数码
手机使用
手机/通讯
MP4/MP3
照相机/摄像机
手机/通讯
手机使用
手机购买
通讯服务
手机使用
手机使用
举报
举报原因(必选):
取消确定举报