dtSette为Datagridview
Private Sub dtSette_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dtSette.EditingControlShowing
Dim EditCell As DataGridViewTextBoxEditingControl
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 e.KeyChar <> Chr(8) And e.KeyChar <> Chr(13) And (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) Then
Beep()
Beep()
e.KeyChar = Chr(0)
End If
End Sub

本文介绍如何在VB.NET中使用Datagridview时,限制单元格编辑只允许输入数字。通过处理EditingControlShowing事件并添加KeyPress事件处理程序,阻止非数字字符的输入。

555

被折叠的 条评论
为什么被折叠?



