Negative number input GridNumericColumn for SfDataGrid
How do I allow input of say -123 into a GridNumericColumn in a SfDataGrid?
The default validation doesn't let you enter a '-' sign.
It Does not let minus sign to be FIRST character input but If you put in a digit, then you can hit the minus sign to and it will make the number into a negative number
So if a user types '-','1','2' then 12 appears in that cell in that column but if they type '1','2',then '-' that works...
Odd!
SIGN IN To post a reply.
2 Replies
JP
Jagadeesan Pichaimuthu
Syncfusion Team
June 20, 2019 12:56 PM UTC
Hi Matthew,
Thanks for using Syncfusion product.
We are working on the requested requirement and we need one more business day to complete it and we will update you with the details on June 21th, 2019.
We appreciate your patience until then.
Regards,
Jagadeesan
JP
Jagadeesan Pichaimuthu
Syncfusion Team
June 21, 2019 11:13 AM UTC
Hi Matthew,
We have analyzed your query, we have restrict other than numeric values in begin edit of GridNumericColumn in source level, so you can achieve your requirement by overriding the GridNumericColumn render for enter into edit mode and set the -1 as a default value while pressing ‘-‘ key.
Please refer the below code example.
|
this.sfDataGrid.CellRenderers.Remove("Numeric");
this.sfDataGrid.CellRenderers.Add("Numeric", new GridNumericCellRendererExt());
public class GridNumericCellRendererExt : GridNumericCellRenderer
{
string previewInputText1 = string.Empty;
protected override void OnKeyPress(DataColumnBase dataColumn, Syncfusion.WinForms.GridCommon.ScrollAxis.RowColumnIndex rowColumnIndex,KeyPressEventArgs e)
{
var dataGrid =(SfDataGrid)((this.TableControl.GetType().GetProperty("DataGrid", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic |BindingFlags.Public)).GetValue(this.TableControl));
if (!dataGrid.CurrentCell.IsEditing && e.KeyChar == '-')
{
var previewInputText = ((dataGrid.CurrentCell.CellRenderer.GetType().GetProperty("PreviewInputText", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | BindingFlags.Public)));
previewInputText.SetValue(dataGrid.CurrentCell.CellRenderer, e.KeyChar.ToString());
previewInputText1 = e.KeyChar.ToString();
dataGrid.CurrentCell.BeginEdit();
}
else
base.OnKeyPress(dataColumn, rowColumnIndex, e);
}
protected override void OnInitializeEditElement(DataColumnBase column, Syncfusion.WinForms.GridCommon.ScrollAxis.RowColumnIndex rowColumnIndex,SfNumericTextBox uiElement)
{
var dataGrid =(SfDataGrid)((this.TableControl.GetType().GetProperty("DataGrid", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic |BindingFlags.Public)).GetValue(this.TableControl));
double value;
var previewText = (string) ((dataGrid.CurrentCell.CellRenderer.GetType().GetProperty("PreviewInputText", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic |BindingFlags.Public))).GetValue(dataGrid.CurrentCell.CellRenderer);
if (double.TryParse(previewInputText1, out value) || previewInputText1 == string.Empty)
base.OnInitializeEditElement(column, rowColumnIndex, uiElement);
else
{
uiElement.Value = -1;
uiElement.Focus();
base.OnInitializeEditElement(column, rowColumnIndex, uiElement);
}
}
} |
Sample Location: https://www.syncfusion.com/downloads/support/forum/145385/ze/NegativeValue-1531231143
Let us know whether this helps also if you need any further assistance on this.
Regards,
Jagadeesan
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
MA Matthew
- Jun 19, 2019 06:09 PM UTC
- Jun 21, 2019 11:13 AM UTC