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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Negative number input GridNumericColumn for SfDataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

145385 Jun 19,2019 06:09 PM UTC Jun 21,2019 11:13 AM UTC WinForms 2
loading
Tags: SfDataGrid
Matthew
Asked On June 19, 2019 06:55 PM UTC

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!





Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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 


Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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); 
        } 
    } 
} 
  
 
 Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon