ArgumentNullException after canceling editing nullable column on Escape

I have a column generator for SfDataGrid that accepts user settings. The current bug is that when pressing Escape on an empty cell value, an exception is thrown: 

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'nullableType')
   at System.ArgumentNullException.Throw(String paramName)
   at System.Nullable.GetUnderlyingType(Type nullableType)
   at Syncfusion.Data.Helper.ValueConvert.ChangeType(Object value, Type type, IFormatProvider provider, String format, Boolean returnDBNullIfNotValid)
   at Syncfusion.Data.Helper.ValueConvert.ChangeType(Object value, Type type, IFormatProvider provider, Boolean returnDBNullIfNotValid)
   at Syncfusion.Data.Helper.ValueConvert.ChangeType(Object value, Type type, IFormatProvider provider)
   at Syncfusion.UI.Xaml.Grid.GridCurrentCellManager.CommitCellValue(Boolean isNewValue)
   at Syncfusion.UI.Xaml.Grid.GridCurrentCellManager.HandleKeyNavigation(KeyEventArgs args, RowColumnIndex rowColumnIndex)
   at Syncfusion.UI.Xaml.Grid.GridSelectionController.ProcessKeyDown(KeyEventArgs args)
   at Syncfusion.UI.Xaml.Grid.GridSelectionController.HandleGridKeyDown(KeyEventArgs args)
   at Syncfusion.UI.Xaml.Grid.GridSelectionController.HandleKeyDown(KeyEventArgs args)
   at Syncfusion.UI.Xaml.Grid.SfDataGrid.OnPreviewKeyDown(KeyEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
   at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)

Example of creating a column for currency: 

case ColumnDataType.Currency:
if(columnProps is not CurrencyColumnProperties currencyProps)
return new GridCurrencyColumn();

return new GridCurrencyColumn
{
MappingName = columnProps.MappingName,
HeaderText = columnProps.HeaderText,
TextAlignment = TextAlignment.Center,
TextWrapping = TextWrapping.Wrap,
AllowFiltering = true,
AllowSorting = true,
AllowGrouping = true,
AllowEditing = true,
CurrencyDecimalSeparator = ",",
CurrencyGroupSeparator = " ",
CurrencyGroupSizes = [3],
CurrencyDecimalDigits = 2,
CurrencySymbol = currencyProps.Symbol,
AllowDragging = true,
Width = columnProps.HeaderWidth,
AllowNullValue = true,
NullText = string.Empty,
ColumnMemberType = typeof(decimal?)
};

7 Replies 1 reply marked as answer

SR Senthilkumar Ranganathan Syncfusion Team September 9, 2025 11:33 AM UTC

Hi Artem,

We have reviewed your query based on the information you provided. We attempted to replicate the reported scenario by canceling the editing in a nullable column by pressing the Escape key in a simple sample. However, we were unable to replicate the issue you described, as it is working as expected on our end.

We have attached the sample and video for your reference. Kindly review them. To assist you further, we kindly request the following additional details about your scenario:

Customizations
: Have you applied any custom logic related to editing, such as handling key events, overriding commit behavior, or modifying value conversion? If so, please share those details.

Modified Sample
: Please modify the attached sample to reproduce the issue on your end and share the updated version with us.

Providing these details will help us better understand the issue and offer a more accurate and effective solution.

Regards,
Senthilkumar Ranganathan.

Attachment: SampleVideo_65762f3.zip


AR Artem September 9, 2025 01:10 PM UTC

I forgot to mention that I am using dynamic data source binding which I defined in my example. I have also attached my screen recording. Try to reproduce the error this time.


Attachment: SfDataGrid_Demo_bb30e873.zip


AR Artem replied to Senthilkumar Ranganathan September 9, 2025 01:14 PM UTC

I forgot to mention that I am using dynamic data source binding which I defined in my example. I have also attached my screen recording. Try to reproduce the error this time.


Attachment: SfDataGrid_Demo_3b39760b.zip


NS Nicholas Shaffer replied to Artem Kovalchuk September 10, 2025 09:54 AM UTC

Thanks!!!!


Attachment: SfDataGrid_Demo_3b39760b.zip 



RM Rabina Murugan Syncfusion Team September 10, 2025 02:15 PM UTC

Artem,


We have investigated the reported scenario. Since you're using a dynamic data source, the nullable value might not be handled correctly, which causes an ArgumentNullException when pressing the Escape key during editing.

To resolve this, please set the UseBindingValue property to true. This ensures that the binding retrieves the value properly.

Code snippet to set UseBindingValue:
 

 var currencyColumn = new GridCurrencyColumn

  {

      MappingName = "Price",

      HeaderText = "Price",

      TextAlignment = TextAlignment.Center,

      TextWrapping = TextWrapping.Wrap,

      AllowFiltering = true,

      AllowSorting = true,

      AllowGrouping = true,

      AllowEditing = true,

      CurrencyDecimalSeparator = ",",

      CurrencyGroupSeparator = " ",

      CurrencyGroupSizes = [3],

      CurrencyDecimalDigits = 2,

      CurrencySymbol = "$",

      AllowDragging = true,

      Width = 200,

      UseBindingValue = true,

      AllowNullValue = true,

      NullText = string.Empty,

      ColumnMemberType = typeof(decimal?)

  };

 


Find the modified sample demo and video in the attachment.


Please let us know if you need any further assistance.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_Video_e1dc8c90.zip

Marked as answer

AR Artem replied to Rabina Murugan September 10, 2025 02:26 PM UTC

Thank you very much, that was indeed the problem.



RM Rabina Murugan Syncfusion Team September 11, 2025 05:06 AM UTC

Artem,

 

You're welcome. We are closing this forum now. Please get back to us if you need any further assistance, we will be happy to help you.


Loader.
Up arrow icon