Numbers only cell
Hi, how can I make a GridControl cell accept numbers only (including negative, and decimal points)?
I have tried using:
GridControl1(1, 2).CellType = GridCellTypeName.MaskEdit
GridControl1(1, 2).MaskEdit.Mask = ......... tried everything I can think off ........
I know that I can also use a NumericUpDown Cell Type, but I don't want the up and down arrows.
How can I achieve this?
Kind Regards
Mike
SIGN IN To post a reply.
5 Replies
AR
Arulpriya Ramalingam
Syncfusion Team
April 10, 2017 11:32 AM UTC
Hi Mike,
Thanks for your interest in Syncfusion products.
We have provided the support for the following numeric cell types in GridControl.
- IntegerTextBox
- DoubleTextBox
- PercentageTextBox
For more information, please refer the below link,
UG Link: https://help.syncfusion.com/windowsforms/grid/enhanced-cell-types#registering-custom-cell-types
The DoubleTextBox CustomCellType can be used to achieve your scenario. Please make use of below code and sample,
Code snippet
|
RegisterCellModel.GridCellType(Me.gridControl1, CustomCellTypes.DoubleTextBox)
Me.gridControl1.ColStyles(1).CellType = CustomCellTypes.DoubleTextBox.ToString() |
Note
The Syncfusion.GridHelperClasses.Windows.dll assembly should be added to the reference.
Dash Board sample: <Install Location>\Syncfusion\EssentialStudio\<Product Version>\Windows\Grid.Windows\Samples\Custom Cell Types\Editor Cell Demo
Regards,
Arulpriya
MN
mike newett
April 11, 2017 08:37 PM UTC
Hi,
I have already looked at the IntegerTextBox & DoubleTextBox, but they do not meet my requirements.
I need to be able to enter any numeric valve into a cell.
There may be times when my users need to enter an integer value into a cell, and other times when they need to enter a value with many decimal points into the same cell. These can be negative or positive numbers.
I cannot restrict the type of numeric input.
Any thing else I can try.
Kind Regards
Mike
AR
Arulpriya Ramalingam
Syncfusion Team
April 12, 2017 01:26 PM UTC
Hi Mike,
Thanks for your update.
By default, GridControl does not have extensibility to customize the decimal digit format and your requirements in the IntegerTetBox and DoubleTextBox . We can achieve your scenario by workaround. It can be achieved by customizing CurrentCellKeyPress event. In the below sample, we have restricted the alphabetical characters for a particular cell and allowed only numeric characters, minus and decimal point as per your requirement. Please make use of the below sample and code,
Code snippet
|
'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 |
Arulpriya
MN
mike newett
May 2, 2017 03:22 AM UTC
That work perfectly thanks.
I had to make 1 small change to get it to work.
'Dim keyvalue As Integer = CInt(Fix(e.KeyChar))' throws an error.
I changed it to 'Dim keyvalue As Integer = Asc(e.KeyChar)'
I've only mentioned it in case some one else has a similar problem.
Kind Regards
Mike
AR
Arulpriya Ramalingam
Syncfusion Team
May 2, 2017 06:54 AM UTC
Hi Mike,
Thank you for your feedback.
We are glad to hear that the provided solution is resolved your scenario.
Please let us know if you need any further assistance.
Regards,
Arulpriya
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
MN mike newett
- Apr 7, 2017 07:09 PM UTC
- May 2, 2017 06:54 AM UTC