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.
|
private void SfNumericTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == System.Windows.Forms.Keys.Decimal)
{
e.SuppressKeyPress = true;
sfNumericTextBox1.AppendText(",");
}
} |
Great! It works! Thank you very much!
Can I achieve the same behavior in numeric columns of SfDataGrid, too?
|
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;
}
}
}
} |