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. Image for the cookie policy date

GridCellNumericRendererExt - Add VirtualKey as new value on edit

Hello,

I was able to successfully implement the GridCellNumericRendererExt class to allow for special characters to initiate editing of cells. However, I am unable to determine a way to set that special character as the new value on BeginEdit. Specifically, we have a requirement for a decimal field that allows values without a leading zero (i.e .75). While, the user can double click on the cell to enter BeginEdit and type .75, they are unable to type .75 when the cell is selected and BeginEdit has not started. They are able to do 0.75, but they will not accept this to satisfy the requirement. Is there a way to modify the GridCellNumericRendererExt so that it takes the special character that initiated the edit as the new value?

Steps to reproduce the problem:

1. Implement GridCellNumericRendererExt
2. On a page with SfDataGrid, select the cell you wish to edit WITHOUT entering edit mode
3. Being to type a decimal value with "." as the leading character

You will find that the cell only takes any keystrokes entered after the decimal has been pressed and ignores the decimal character.

Thanks,
Brandon

3 Replies

JG Jai Ganesh S Syncfusion Team July 27, 2016 02:47 AM UTC

Hi Brandon, 
 
You can achieve your requirement to show the special characters while you go to edit mode on the cell by overriding the  OnEditElementLoaded method like below, 
 
protected override void OnEditElementLoaded(object sender, RoutedEventArgs e) 
{ 
    var uiElement = ((DoubleTextBox)sender); 
    uiElement.ValueChanged += OnValueChanged; 
 
    uiElement.Focus(); 
 
    if ((this.DataGrid.EditorSelectionBehavior == EditorSelectionBehavior.SelectAll || this.DataGrid.IsAddNewIndex(this.CurrentCellIndex.RowIndex)) && PreviewInputText == null) 
    { 
        uiElement.SelectAll(); 
    } 
    else 
    { 
        if (PreviewInputText == null || char.IsLetter(PreviewInputText.ToString(), 0)) 
        { 
            var index = uiElement.Text.Length; 
            uiElement.Select(index + 1, 0); 
            return; 
        } 
        double value; 
        double.TryParse(PreviewInputText.ToString(), out value); 
        uiElement.Value = value; 
        uiElement.Text = PreviewInputText.ToString(); 
        var caretIndex = uiElement.Text.IndexOf(PreviewInputText.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal); 
        uiElement.Select(caretIndex + 1, 0); 
    } 
    PreviewInputText = null; 
} 
 
 
Regards, 
Jai Ganesh S 



BH Brandon Hankins July 28, 2016 01:24 PM UTC

This sample appears to be for WPF. We are using UWP. Thanks.


JG Jai Ganesh S Syncfusion Team August 1, 2016 01:48 AM UTC

Hi Brandon, 
 
We have used SfNumericTextBox for GridNumericColumn in UWP platform. In SfNumerictextBox the text is displayed based on the value not in PreviewInputText. So we regret to inform you that, in GridNumericColumn you cannot show the typed special character when begin edit. 
 
Regards, 
Jai Ganesh S 


Loader.
Live Chat Icon For mobile
Up arrow icon