• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Code

Always Begin...
  • 博客园
  • 管理

View Post

DataGirdView 单元格限制内容输入参考(按键时的判断)

限制DataGridView的输入

DataGridView
 1     '******************************************************************************************
2 ''' <summary>AddHandler DGV key press</summary>
3 Private Sub DGV_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvMain.EditingControlShowing
4 Try
5 Dim CurEditrCell As DataGridViewTextBoxEditingControl
6
7 If TypeOf e.Control Is DataGridViewTextBoxEditingControl Then
8 CurEditrCell = CType(e.Control, DataGridViewTextBoxEditingControl)
9 AddHandler CurEditrCell.KeyPress, AddressOf dgvKeyPress
10 End If
11 Catch ex As Exception
12
13 End Try
14 End Sub
15
16 '******************************************************************************************
17 ''' <summary>DGV Cell key press event</summary>
18 Private Sub dgvKeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs)
19 Try
20 With dgvMain
21 If .CurrentCell Is Nothing Then
22 Exit Sub
23 End If
24
25 If (Asc(e.KeyChar) <> Keys.Back) Then
26 Select Case .CurrentCell.ColumnIndex
27 Case 2, 3
28 If (sender.text.length < 10) Then
29 If (e.KeyChar <> Chr(47)) AndAlso ((e.KeyChar > Chr(57)) OrElse (e.KeyChar < Chr(48))) Then
30 e.Handled = True
31 End If
32 Else
33 e.Handled = True
34 End If
35 End Select
36 End If
37
38 End With
39 Catch ex As Exception
40
41 End Try
42 End Sub



posted on 2011-12-27 18:26  老十  阅读(480)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3