Decimal separator in edit mode

Hi, I would like to know if is it possible to achieve this behavior:

I set the culture "it-IT" to the NumberFormatInfo property in order to correctly display numbers with comma as decimal separator, and this is ok.

But I would like to obtain a comma as decimal separator even when I press the dot of the numeric keyboard.

Is it possible?

Thanks.



3 Replies

SN Sudharsan Narayanan Syncfusion Team November 2, 2021 12:33 PM UTC

Hi Emanuele,

Thanks for contacting Syncfusion support,

We have checked the reported issue that “Decimal separator in edit mode” from our end. We have prepared the sample to achieve the requirement in the key down event. So please find the code snippet and sample from the below location,

Sample: https://www.syncfusion.com/downloads/support/forum/170072/ze/DecimalSeparator-1453334427

Code Snippet:

 
private void SfNumericTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) 
        { 
            if(e.KeyCode == System.Windows.Forms.Keys.Decimal) 
            { 
                e.SuppressKeyPress = true; 
                sfNumericTextBox1.AppendText(","); 
            } 
        } 

Please check the above sample and let me know, if you have any other concerns. We are happy to assist you.

Regards,
Sudharsan



EM Emanuele November 2, 2021 03:13 PM UTC

Great! It works! Thank you very much!

Can I achieve the same behavior in numeric columns of SfDataGrid, too?



VS Vijayarasan Sivanandham Syncfusion Team November 3, 2021 02:29 PM UTC

Hi Emanuele,

Thanks for the update.

Your requirement can be achieved by override the OnInitializeEditElement method and customization the KeyDown event of SfNumericTextBox in GridNumericCellRendererExt in SfDatGrid. Please refer the below code snippet, 
this.sfDataGrid.CellRenderers.Remove("Numeric"); 
this.sfDataGrid.CellRenderers.Add("Numeric", new GridNumericCellRendererExt()); 
 
public class GridNumericCellRendererExt : GridNumericCellRenderer 
{ 
        protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfNumericTextBox uiElement) 
        { 
            base.OnInitializeEditElement(column, rowColumnIndex, uiElement); 
            uiElement.KeyDown += UiElement_KeyDown; 
        } 
 
        private void UiElement_KeyDown(object sender, KeyEventArgs e) 
        { 
            if (e.KeyCode == Keys.Decimal) 
            {                 
                e.SuppressKeyPress = true; 
 
                //get the SfNumericTextBox  
                var numericTextBox = sender as SfNumericTextBox; 
 
                //split the text based on decimal separator 
                var textcollection = numericTextBox.Text.Split(','); 
                foreach (var text in textcollection) 
                { 
                    //move the cursor after the decimal separator while pressing the dot of the numeric keyboard  
                    numericTextBox.SelectionStart = text.Length + 1; 
                    numericTextBox.SelectionLength = 0; 
                    break; 
                } 
            } 
        } 
} 

Sample Link: https://www.syncfusion.com/downloads/support/forum/170120/ze/SfDataGridDemo1483585870

For more information related to Customize Column Renderer, please refer the below user guide documentation link, 

Please let us know if you have any concerns in this. 
 
Regards, 
Vijayarasan S 


Loader.
Up arrow icon