c转vb.net

weixin_38048154 2016-04-24 01:58:53
我只会vb.net,网上找了一段。用网页转成vb.net后有错误,请帮忙转一下!谢谢!
代码的意思是控制datagridview单元格只能输入正数,源码如下:
Private Sub DataGridView_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs)
If TypeOf e.Control Is DataGridViewTextBoxEditingControl Then
Dim dgv As DataGridView = DirectCast(sender, DataGridView)
Dim tb As DataGridViewTextBoxEditingControl = DirectCast(e.Control, DataGridViewTextBoxEditingControl)
tb.KeyPress -= New KeyPressEventHandler(AddressOf dataGridViewTextBox_KeyPress)
If dgv.CurrentCell.OwningColumn.Name = "" Then
tb.KeyPress += New KeyPressEventHandler(AddressOf dataGridViewTextBox_KeyPress)
End If
End If
End Sub

Private Shared Sub dataGridViewTextBox_KeyPress(sender As Object, e As KeyPressEventArgs)
'这里还可加长度判断
If (e.KeyChar >= DirectCast(Keys.D0, [Char]) AndAlso e.KeyChar <= DirectCast(Keys.D9, [Char])) OrElse e.KeyChar = DirectCast(Keys.Delete, [Char]) OrElse e.KeyChar = DirectCast(Keys.Back,
[Char]) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================

翻译后的如下:
Private Sub DataGridView_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs)
If TypeOf e.Control Is DataGridViewTextBoxEditingControl Then
Dim dgv As DataGridView = DirectCast(sender, DataGridView)
Dim tb As DataGridViewTextBoxEditingControl = DirectCast(e.Control, DataGridViewTextBoxEditingControl)
tb.KeyPress -= New KeyPressEventHandler(AddressOf dataGridViewTextBox_KeyPress)
If dgv.CurrentCell.OwningColumn.Name = "" Then
tb.KeyPress += New KeyPressEventHandler(AddressOf dataGridViewTextBox_KeyPress)
End If
End If
End Sub

Private Shared Sub dataGridViewTextBox_KeyPress(sender As Object, e As KeyPressEventArgs)
'这里还可加长度判断
If (e.KeyChar >= DirectCast(Keys.D0, [Char]) AndAlso e.KeyChar <= DirectCast(Keys.D9, [Char])) OrElse e.KeyChar = DirectCast(Keys.Delete, [Char]) OrElse e.KeyChar = DirectCast(Keys.Back, [Char]) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================



Work8862
...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复

477

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧