BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hi,
When editing in GridNumericColumn the minus sign is not immediately shown. I am aware of previous threads and solutions such as these:
Start editing not only with numbers, but also with minus sign | WPF Forums | Syncfusion
Customize the edit mode behavior of cells | WPF - SfDataGrid (syncfusion.com)
Editing in WPF DataGrid control | Syncfusion
BUT they are only part of the solution because it works for GridTextColumn but not for GridNumericColumn.
Reproduction steps:
Expected behavior:
Regards
Carlo
Hi Carlo da Veiga Monteiro,
As you said in the previous update, entering the edit mode via minus in SfDataGrid
can be achieved by customizing the SfDataGrid class and overriding its
OnTextInput method. For more information related to entering edit via minus key,
please refer to the below user guide documentation link,
UG Link: https://help.syncfusion.com/wpf/datagrid/editing#allow-editing-when-pressing-minus-key
KB Link: https://www.syncfusion.com/kb/3823/how-to-customize-edit-mode-behavior-of-gridcell-in-sfdatagrid
However, your
requirement to display a minus key value while the enter edit mode in SfDataGrid
can be achieved by overriding the GridCellNumericRenderer and customizing
the OnEditElementLoaded method. Please refer to the below code snippet,
//Removes Default renderer. sfDataGrid.CellRenderers.Remove("Numeric"); //Adds Custom renderer. sfDataGrid.CellRenderers.Add("Numeric", new GridCellNumericRendererExt());
public class GridCellNumericRendererExt : GridCellNumericRenderer { protected override void OnEditElementLoaded(object sender, RoutedEventArgs e) { var uiElement = ((DoubleTextBox)sender); uiElement.ValueChanged += OnValueChanged;
uiElement.Focus();
if (uiElement.IsReadOnly) { PreviewInputText = null; uiElement.SelectAll(); return; }
if ((this.DataGrid.EditorSelectionBehavior == EditorSelectionBehavior.SelectAll || this.DataGrid.IsAddNewIndex(this.CurrentCellInde { 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; }
private void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { base.CurrentRendererValueChanged(); }
protected override void OnWireEditUIElement(DoubleTextBox uiElement) { uiElement.ValueChanged -= OnValueChanged; } } |
UG Link: https://help.syncfusion.com/wpf/datagrid/column-types#customize-column-renderer
Find the sample in the attachment.
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hi Vijayarasan Sivanandham,
It works great. Thank you for the fast response and solution!
Regards,
Carlo
Carlo da Veiga Monteiro,
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.