We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Numbers only cell

Thread ID:





129897 Apr 7,2017 07:09 PM UTC May 2,2017 06:54 AM UTC WinForms 5
Tags: GridControl
mike newett
Asked On April 7, 2017 07:09 PM UTC

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


Arulpriya Ramalingam [Syncfusion]
Replied On 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, 

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() 

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 


mike newett
Replied On April 11, 2017 08:37 PM UTC


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


Arulpriya Ramalingam [Syncfusion]
Replied On 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 
                             End If 
                             'To allow minus at starting position 
                             If keyvalue = Minus AndAlso selectionStart = 0 Then 
                             End If 
                            'To allow decimal point only once 
                             If (keyvalue = decimalPoint) AndAlso text.IndexOf(".") = -1 Then 
                             End If 
                             ' To restrict other chars 
                             e.Handled = True 
              End If 
End Sub 


mike newett
Replied On 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


Arulpriya Ramalingam [Syncfusion]
Replied On 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.    



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon