none
請問 DataGridView 要如何處理 Cell 只能輸入帶小數點的數字呢? RRS feed

  • 問題

  • 程式碼已經可以限制 Cell 只能輸入數字和小數點,但不知道要怎麼限定小數點只能輸入一個和限定輸入的小數位數
    請問要怎麼做?

     Dim WithEvents EditingControl As DataGridViewTextBoxEditingControl
        Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
            EditingControl = CType(e.Control, DataGridViewTextBoxEditingControl)
        End Sub
    
        Private Sub EditingControl_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles EditingControl.KeyPress
            If (Not Char.IsDigit(e.KeyChar)) AndAlso (Not Char.IsControl(e.KeyChar) AndAlso (Not e.KeyChar = ".")) Then
                e.Handled = True
            End If
        End Sub

    2012年6月21日 上午 01:28

解答

所有回覆