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);
}
}
} |