RegisterCellModel.GridCellType(Me.gridControl1, CustomCellTypes.DoubleTextBox)
Me.gridControl1.ColStyles(1).CellType = CustomCellTypes.DoubleTextBox.ToString() |
'Event triggering
AddHandler Me.gridControl1.CurrentCellKeyPress, AddressOf GridControl1_CurrentCellKeyPress
'Event Customization
Private Sub GridControl1_CurrentCellKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
Dim currentCell As GridCurrentCell = Me.gridControl1.CurrentCell
If currentCell IsNot Nothing AndAlso currentCell.RowIndex=1 AndAlso currentCell.ColIndex=1 Then
Dim decimalPoint As Integer = 46
Dim zero As Integer = 48
Dim nine As Integer = 57
Dim Minus As Integer = 45
Dim keyvalue As Integer = CInt(Fix(e.KeyChar))
Dim renderer = TryCast(currentCell.Renderer, GridTextBoxCellRenderer)
Dim selectionStart As Integer = renderer.TextBox.SelectionStart
Dim text As String = renderer.ControlText
'To allow only numeric values
If (keyvalue = CInt(Keys.Back)) OrElse ((keyvalue >= zero) AndAlso (keyvalue <= nine)) Then
Return
End If
'To allow minus at starting position
If keyvalue = Minus AndAlso selectionStart = 0 Then
Return
End If
'To allow decimal point only once
If (keyvalue = decimalPoint) AndAlso text.IndexOf(".") = -1 Then
Return
End If
' To restrict other chars
e.Handled = True
End If
End Sub |