2013-08-30 60 views
0

3位數這是我接受只在文本框數字代碼:如何設置DataGridView的細胞接受vb.net

Select Case e.KeyChar 
     Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", vbBack 
      e.Handled = False 
     Case Else 
      e.Handled = True 
End Select 

可我也用這幾樣代碼的單元格datagridview ?,還有如何限制no。單元格中的字符會自動顯示,這意味着不會有msgbox提示用戶。

謝謝。

回答

1

您可以嘗試這一塊上的DataGridView的編輯控制編碼的

Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing 
Try 

    If 'Set the column/cell 

     AddHandler e.Control.KeyPress, AddressOf TextNumberKeypress 

    End If 

Catch ex As Exception 
    '... 
End Try 

末次

Sub TextNumberKeypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 
    'Put the validations for your cell 
    End Sub 
+0

你是什麼意思「「設置列/單元格 – Matthew

+0

無視我的第一評論,這是最好的!,謝謝先生!它確實節省了我的時間:) – Matthew

+0

它不是先生,它的小姐!! –