DragDrop without selected item causing critical error

Hello.

After updating the nugets to get the fix for the TreeView Dragging issue I posted before, i have encountered the following issue. Please also refer to the video for clarity.

When using the drag and drop function in the SfDataGrid, when a row, or multiple rows are selected, everything runs smoothly.

However, if the selection is cleared, or there was no selection to begin with, the program will crash on a null reference exception.

Since i do not hook any events to the RowDragDropController , i believe this might be an issue within the controller itself, not able to either cancel when no item is selected, or not selecting the item the mouse is hovering over.

If you need more information, please let me know.

My project is built on .Net 5.0


Addition:
If there is any way to circumvent this issue for now, please let me know.

I have tried adding an event to RowDragDropController.DragStart, where i check for the datagrid's selected items, and set the event to handled if the count equals 0. But the break occurs before this event is fired, so unfortunatly this is no use.


Attachment: dragdrop_video_541cd950.zip


5 Replies 1 reply marked as answer

SS Sampathnarayanan Sankaralingam Syncfusion Team February 4, 2022 12:27 PM UTC

Hi Kavin,


We have checked the issue in our sample with latest Syncfusion version 19.4.0.48 but we are unable to reproduce the issue. Please find the video illustration and the sample from the below given links.


Video Link : https://www.syncfusion.com/downloads/support/forum/172545/ze/Sample_Video-2115097615


Sample Link : https://www.syncfusion.com/downloads/support/forum/172545/ze/Sample258823299


Please have a look at this sample and let us know if we have missed any customization done in your application. Otherwise try to reproduce the reported issue in this sample and revert to us with the modified sample. It will be more helpful for us to find the exact cause for the issue and to provide a prompt solution.


Regards,

Sampath Narayanan.S



KS Kevin Schrasser February 8, 2022 07:47 AM UTC

Hello Sampathnarayanan

I see indeed that it does not recreate the issue.

However, for me it persists and i am unable to find a cause for it so far.

This is how my current grid is defined in the Xaml

<sf:SfDataGrid x:Name="gridVariable" Grid.Row="0" AllowDraggingRows="True" AllowDrop="True" AllowSorting="False" ScrollViewer.VerticalScrollBarVisibility="Auto"

                                       HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" ColumnSizer="star" Margin="6,3,3,3" ScrollViewer.HorizontalScrollBarVisibility="Disabled"

                                       ItemsSource="{Binding gridVariableData}" SelectionMode="Extended" SelectionUnit="Row" AllowEditing="True" AllowDeleting="False"

                                       CurrentCellBeginEdit="gridVariable_PreparingCellForEdit"

                                       CurrentCellEndEdit="gridVariable_CellEditEnding"

                                       MouseDoubleClick="VarTable_CellMouseDoubleClick"

                                       PreviewMouseLeftButtonDown="VarGridMouseLeftButtonDown"

                                       MouseLeftButtonUp="VarGridMouseLeftButtonUp"

                                       MouseMove="VarGridMouseMove" MouseLeave="grid_MouseLeave"

                                       DragEnter="gridVariable_DragEnter"

                                       Drop="gridVariable_Drop"

                                       DragOver="grid_DragMove"

                                       KeyDown="grid_KeyDown"

                                       ItemsSourceChanged="VarTable_ItemsSourceChanged">

                            <sf:SfDataGrid.Columns>

                                <sf:GridTextColumn MappingName="Variable" AllowEditing="False" ColumnSizer="AutoWithLastColumnFill"/>

                                <sf:GridTextColumn MappingName="Unit" AllowEditing="False" TextAlignment="Right" ColumnSizer="AutoWithLastColumnFill"/>

                                <sf:GridTextColumn MappingName="Value" ColumnSizer="AutoWithLastColumnFill"/>

                            </sf:SfDataGrid.Columns>

                        </sf:SfDataGrid>


A secondary grid is defined as below:

<sf:SfDataGrid x:Name="gridCalibration" ItemsSource="{Binding Path=gridCalibrationData}" Grid.Row="2" AllowDraggingRows="True" AllowDrop="True" AllowSorting="False"

                                       AllowEditing="True" AllowDeleting="False" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" Height="Auto"

                                       VerticalAlignment="Stretch" Width="Auto" ColumnSizer="Star" Margin="6,3,3,3" ScrollViewer.HorizontalScrollBarVisibility="Disabled"

                                       SelectionMode="Extended" SelectionUnit="Row"

                                       CurrentCellEndEdit="gridCalib_CellEditEnding"

                                       PreviewKeyDown="grid_KeyDown"

                                       PreviewMouseLeftButtonDown="CalGridMouseLeftButtonDown"

                                       MouseLeftButtonUp="CalGridMouseLeftButtonUp"

                                       MouseMove="CalGridMouseMove" MouseLeave="grid_MouseLeave"

                                       DragEnter="gridCalibration_DragEnter" Drop="gridCalibration_Drop"

                                       DragOver="grid_DragMove"

                                       CurrentCellBeginEdit="gridCalib_CellEditBegin"

                                       ItemsSourceChanged="CalTable_ItemsSourceChanged"

                                       SelectionChanging="gridCalibration_SelectionChanging">

                            <sf:SfDataGrid.Columns>

                                <sf:GridTextColumn MappingName="Calibration" AllowEditing="False" ColumnSizer="AutoWithLastColumnFill" />

                                <sf:GridTextColumn MappingName="Unit" AllowEditing="False" TextAlignment="Right" ColumnSizer="AutoWithLastColumnFill"/>

                                <sf:GridTextColumn MappingName="Value" ColumnSizer="AutoWithLastColumnFill"/>

                            </sf:SfDataGrid.Columns>

                        </sf:SfDataGrid>


Both grids show the same error, with the following stack:

System.NullReferenceException

  HResult=0x80004003

  Message=Object reference not set to an instance of an object.

  Source=Syncfusion.SfGrid.WPF

  StackTrace:

   at Syncfusion.UI.Xaml.Grid.GridCell.GridCell_PreviewMouseMove(Object sender, MouseEventArgs 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.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)

   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

   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 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

   at System.Windows.Threading.Dispatcher.Run()

   at System.Windows.Application.RunDispatcher(Object ignore)

   at System.Windows.Application.RunInternal(Window window)

   at System.Windows.Application.Run()

   at DirectBlue_Tool_WPF.App.Main()

According to the stack it starts at Gridcell_PreviewMouseMove, which, as far as i know, have nothing hooked to, though maybe i'm overlooking somthing from the other event hooks?



SS Sampathnarayanan Sankaralingam Syncfusion Team February 10, 2022 02:46 AM UTC

Hi Kavin,


We have created the sample with your provided code but still we are not able to replicate the issue in our end. However, we have included a fix for an issue with the provided call stack from our version 19.4.0.48. So please check and let us know whether you are facing the issue even in version 19.4.0.48. Please revert to us with more details if you still facing this issue.


Regards,

Sampath Narayanan.S


Marked as answer

KS Kevin Schrasser February 10, 2022 07:04 AM UTC

Hello Sampath,

There was indeed an update (even to 19.4.0.50), and the issue does not persist in that version.

Thank you very much for your help.


Regards,
Kevin.



MA Mohanram Anbukkarasu Syncfusion Team February 14, 2022 03:06 AM UTC

Hi Kevin,  

We are glad to know that the reported issue has been resolved in your end. Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon