以下是只能輸入數(shù)字和小數(shù)點,并且小數(shù)點只能輸入一次
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設,掇刀企業(yè)網(wǎng)站建設,掇刀品牌網(wǎng)站建設,網(wǎng)站定制,掇刀網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,掇刀網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
If Char.IsDigit(e.KeyChar) or e.KeyChar = Chr(8) or e.KeyChar = "." Then
If e.KeyChar = "." And InStr(TextBox1.Text, ".") 0 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End Sub
第一部、先定義一個單元格操作變量,如下
Dim cellEdit As DataGridViewTextBoxEditingControl = Nothing
第二部、然后在在控件的EditingControlShowing事件中添加入下代碼,參考如下:
Private Sub DataGridView3_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView3.EditingControlShowing
cellEdit = CType(e.Control, DataGridViewTextBoxEditingControl)
cellEdit.SelectAll()
AddHandler cellEdit.KeyPress, AddressOf dataGridView3_KeyPress
End Sub
第三部:在要控制的列加入控件鍵盤按鈕的代碼,如下面ROLL列是要控制的列
Private Sub dataGridView3_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles DataGridView3.KeyPress
Dim i As Integer = DataGridView3.CurrentCellAddress.X
Dim ColumnName As String = DataGridView3.Columns(i).Name
If (ColumnName = "rollno") Then
If Not Char.IsDigit(e.KeyChar) And e.KeyChar Chr(8) Then
e.Handled = True
End If
End If
End Sub
可以用VB6里的函數(shù)
isnumeric()
比如要判斷文本框里的內容是否數(shù)字
if isnumeric(TextBox1.text) Then
msgbox("是數(shù)字!")
else
msgbox("不是數(shù)字!")
end if
input type="text" maxlength="11" /這是控制最大輸入字數(shù)至于不能少于11個字,需要在點擊保存按鈕時,通過.length來控制