InvalidOperationException using C1DragDropManager

Posted by: trancuong200495 on 10 January 2018, 3:32 pm EST

    • Post Options:
    • Link

    Posted 10 January 2018, 3:32 pm EST

    Recently I’m been working on a project using many dragdrop.Everything works fine when I use C1DragDropManager for 2 C1DataGrid.But the past few days I kept getting InvalidOperationException when use C1DragDropManager for C1TreeView and i figured that this exception seems to be caused by C1DragDropManager .So far i haven’t found any solutions.Can anyone help me with this

    StackTrace and Sample Code

  • Posted 10 January 2018, 6:06 pm EST

    Note:This exception occurs when dragging from treeview to grid(not regularly)

    throwed message “Specified element is already the logical child of another element. Disconnect it first”

    Sample code WPF_DataGridDragDropRows_CS.zip

  • Posted 11 January 2018, 5:56 pm EST

    Hi,

    Thank you for sharing the application.

    We could observe the exception, however its occurrence is sporadic. Also, it seems this issue is not specific to ComponentOne controls.

    Anyhow, could you try using the following code-snippet in C1DragDropManager’s DragStart event:

    var item = e.DragSource as C1TreeViewItem;
    if (item != null)
    {
          Dispatcher.BeginInvoke(new Action(() =>
          {
                   e.Effect = DragDropEffect.Move;
          }));
    }
    

    Meanwhile. we are also discussing the issue with the developer [Tracking ID: 304854]. We will update you the information we receive from them.

    Thanks,

    Ruchir Agarwal

  • Posted 11 January 2018, 9:41 pm EST

    Hi again,

    Also, you may implement DispatcherUnhandledException in your project startup class as below so application ignores the exception when it’s raised.


    public partial class App : Application

    {

    public App()

    {

    Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;

    }

    private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)

    {

    e.Handled = true;

    }

    }


    Hope, it will help you

    Thanks,

    Ruchir Agarwal

  • Posted 9 July 2020, 6:41 am EST

    Hey,

    I ran into a similar kind of issue.

    In my case the issue is C1DragDropManager throws and exception:

    “Specified element is already the logical child of another element. Disconnect it first.”

    I have posted the stacktrace below:

    System.InvalidOperationException

    HResult=0x80131509

    Message=Specified element is already the logical child of another element. Disconnect it first.

    Source=PresentationFramework

    StackTrace:

    at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)

    at System.Windows.FrameworkElement.AddLogicalChild(Object child)

    at C1.WPF.UIElementAdorner…ctor(UIElement adornedElement, UIElement elem)

    at C1.WPF.C1DragDropManager.DoDragDrop(UIElement source, MouseEventArgs e, DragDropEffect effect)

    at C1.WPF.C1DragDropManager.source_MouseMove(Object sender, MouseEventArgs e)

    at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)

    at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

    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.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)

    at System.Windows.Input.InputManager.ProcessStagingArea()

    at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)

    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.Application.RunDispatcher(Object ignore)

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

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

    at System.Windows.Application.Run()

    at Bca.Mktg.GMAS.UI.Shell.App.Main()

    This issue is intermittent and breaks the application, I have handled it as mentioned here but the visual elements or the Borders of the TargetMarker and the SourceMarker get stuck on the view port and doesn’t let me drag and drop further.

    Any resolution to this is appreciated.

    Thanks

  • Posted 10 July 2020, 12:09 am EST

    Hello,

    Would it be possible for you to share a demo application to show the issue? Also, as this issue was fixed in *.608 build version, please share the ComponentOne version you are using. Trying to replicate, I cannot see the exception with the latest version.

    Regards,

    Ruchir

  • Posted 10 July 2020, 1:56 am EST

    I am using the ComponentOne version 4.0.20121.237 and the exception is from the ComponentOne dll. Can you let me know the exact version after which it was fixed?

  • Posted 10 July 2020, 7:00 am EST

    Please try upgrading to 2018v3 release version: 4.0.20183.618, through C1Live. Also, you can download the assemblies manually from here: http://prerelease.componentone.com/dotnet40/c1wpflibrary/2018-t3/

    Regards,

  • Posted 30 July 2020, 2:54 am EST

    I have updated to the version mentioned above. Now that issue has been fixed.

    I need to use a custom grabbing cursor for the drag and drop.

    In the drag start event I have overriden the cursor with the custom cursor and after dragdrop I have changed the mouse to arrow but when the element is dragged to another element which is not a drop target and left there the cursor stays as the grabbing cursor. Is there any event that triggers after the an element is dragged and left anywhere. Is there anyway to change the mouse cursor outside of the registered targets.

    Any help would be appreciated.

    Thanks

  • Posted 31 July 2020, 5:14 am EST - Updated 3 October 2022, 11:52 pm EST

    Hi,

    When a dragged element is dropped, the DragDrop event is triggered. You can set the Cursor back to default inside the handler of this event.

    However, since you are dealing with cursors based on the dropping validity of elements, if you allow I would like to suggest you to modify the cursor as the drag happens. Please see, attached video for reference wherein the cursor changes to ‘No’ when the element is dragged over an invalid drop element.



    To implement such behavior, one needs to check whether the element under mouse is valid/invalid and accordingly change cursor, inside the DragOver event handler. I have attached the application for you.

    Regards,

    Ruchir

    DragDrop_TreeViewWPF.zip

  • Posted 5 August 2020, 12:55 am EST

    I have upgraded the componentOne dlls from 4.0.20121.237 to 4.0.20183.611 but the application is crashing unexpectedly at random places. It is sporadic. The application prior to upgrading the dlls wasn’t crashing.

    The accordions are taking way too long to load which causes the application to go into program not responding mode, it was not the case when I was using the older version dlls. The upgrade of these dlls has made the application unstable. Any idea why this might be happening? Is there a stable version other than the one mentioned which would tackle this issue?

    Attaching an error log:

    When a column header is clicked the application crashes.

    System.ArgumentNullException

    HResult=0x80004003

    Message=Value cannot be null.

    Parameter name: element

    Source=PresentationCore

    StackTrace:

    at MS.Internal.Media.VisualTreeUtils.AsNonNullVisual(DependencyObject element, Visual& visual, Visual3D& visual3D)

    at System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)

    at C1.WPF.DataGrid.DataGridColumnHeaderPresenter.IsInsideFilter(UIElement element)

    at C1.WPF.DataGrid.DataGridColumnHeaderPresenter.OnTapped(Object sender, C1TappedEventArgs e)

    at C1.WPF.C1TapHelper.#ftg(Object #BQ, RoutedEventArgs #tQ)

    at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)

    at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

    at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)

    at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)

    at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)

    at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

    at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

    at System.Windows.ContentElement.RaiseTrustedEvent(RoutedEventArgs args)

    at System.Windows.Input.InputManager.ProcessStagingArea()

    at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)

    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.Application.RunDispatcher(Object ignore)

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

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

    at System.Windows.Application.Run()

    at Bca.Mktg.GMAS.UI.Shell.App.Main()

    Thanks

  • Posted 6 August 2020, 7:03 am EST

    Hello,

    Thank you for sharing the stack trace, which informs us that you are using C1DataGrid and not C1TreeView.

    Regarding the crash: Since, it happens just on the click of a header, the crash does not occur with a simple application and though, it was not occurring with older version, the crash must be specific to the implementation in your application.

    Also, as the issue is not related to our discussion above related to drag drop and occurs sporadically, as you mention, I would request you to please share a stripped down application so that we can narrow the cause of the issue in your application and assist you further.

    Additionally, can you please confirm whether the device on which the application is crashing, is it a touch device? Can you please share details about your environment also.

    Regards,

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels