zoukankan      html  css  js  c++  java
  • 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



  • 相关阅读:
    .net web开发经典图书总结
    Asp.net Web API实战
    扩展方法之二分查找
    在线转换图片文件等
    如何减少代码中的分支语句
    web插件化解决方案 开发分享
    .NET 4.5 MEF 基于约定的编程模型重典
    所有排序总结(内排序)
    生成zip文件
    open source ESB and integration platform
  • 原文地址:https://www.cnblogs.com/sugartomato/p/2303860.html
Copyright © 2011-2022 走看看