首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将数据视图中的特定列设置为仅在vb.net中输入数字

将数据视图中的特定列设置为仅在vb.net中输入数字
EN

Stack Overflow用户
提问于 2013-09-11 02:25:34
回答 1查看 1.9K关注 0票数 0

这是我的代码,用于将所有列设置为仅输入数字:

代码语言:javascript
运行
复制
Private Sub dvBelt_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dvBelt.EditingControlShowing
    Try
        RemoveHandler e.Control.KeyPress, AddressOf TextNumberKeypress
        AddHandler e.Control.KeyPress, AddressOf TextNumberKeypress

    Catch ex As Exception
        '... 
    End Try
End Sub

Sub TextNumberKeypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)

    If Asc(e.KeyChar) >= 33 And Asc(e.KeyChar) <= 47 Or _
        Asc(e.KeyChar) >= 58 Then
        e.Handled = True
    End If

End Sub

现在我想要的是只设置第一列,只允许输入数字,其余的列可以输入字符串。

谢谢你的帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-11 04:02:11

dvBelt_EditingControlShowing方法中,只有当当前单元格指向第一列并将其注册到特定单元格时,才会注册事件。在C++/Cli中,代码如下所示

代码语言:javascript
运行
复制
void dvBelt_EditingControlShowing(System::Object ^sender, System::Windows::Forms::DataGridViewEditingControlShowingEventArgs ^e) {
try {

    if (this->dvBelt->CurrentCell->ColumnIndex == 0) { // 0 is the column index for the first column
        //do the removing and adding of your kepress event here
    }
} catch (Exception ^ex) {

}}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18731698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档