编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
发新话题
打印

vb 2005中限定datagridview控件中某列只能数字

vb 2005中限定datagridview控件中某列只能数字

各位大虾,

请问在vb 2005中怎么实现 DataGridView控件中某列  (比如第3列)  只能输入数字呢?  谢谢

TOP

晕哦,有哪位大虾能赐教下呢?谢谢.....

TOP

自己參考一下
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.datagridview_methods(VS.80).aspx

TOP

Public EditCell As DataGridViewTextBoxEditingControl

    Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
        EditCell = CType(e.Control, DataGridViewTextBoxEditingControl)
        EditCell.SelectAll()
        '输入屏蔽,委托到自定义的事件
        AddHandler EditCell.KeyPress, AddressOf Cells_KeyPress
    End Sub

    Private Sub Cells_KeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs)
        If DataGridView1.CurrentCellAddress.X = 3 Then
            If e.KeyChar <> Chr(46) And e.KeyChar <> Chr(8) And e.KeyChar <> Chr(13) And (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) Then
                e.Handled = True
            End If
        End If
    End Sub
程序人员写程序,又拿程序换酒钱。 奔驰宝马贵者趣,公交自行程序员。 不见满街漂亮妹,哪个归得程序员。

TOP

谢谢版主,谢谢...

TOP

发新话题