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.
Unfortunately, activation email could not send to your email. Please try again.

Numbers only cell

Thread ID:

Created:

Updated:

Platform:

Replies:

129897 Apr 7,2017 03:09 PM May 2,2017 02:54 AM Windows Forms 5
loading
Tags: GridControl
mike newett
Asked On April 7, 2017 03:09 PM

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
 



Arulpriya Ramalingam [Syncfusion]
Replied On April 10, 2017 07:32 AM

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

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 


mike newett
Replied On April 11, 2017 04:37 PM

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

Arulpriya Ramalingam [Syncfusion]
Replied On April 12, 2017 09:26 AM

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 


mike newett
Replied On May 1, 2017 11:22 PM

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

Arulpriya Ramalingam [Syncfusion]
Replied On May 2, 2017 02:54 AM

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

CONFIRMATION

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.

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.

;