Drag'n'drop and winforms

5 posts, 0 answers
  1. Stéphane
    Stéphane avatar
    6 posts
    Member since:
    Mar 2012

    Posted 28 Jan 2014 Link to this post

    Hello,

    I upgraded from version 2012.3.1129.40 to 2013.3.1204.40.
    In our application, we can drag a node from a treeview and drop it in a WinForms control.
    With the old version of Telerik, we were able to change the TreeViewDragCue object from the WinForm control, like this:
    RadDragAndDropManager.Options.Effects = ConvertToWpfEffects(effects);
    var l_cue = RadDragAndDropManager.Options.DragCue as Telerik.Windows.Controls.TreeView.TreeViewDragCue;
    if (l_cue != null)
    {
        switch (effects)
        {
            case DragAndDropEffects.Copy:
                l_cue.DragActionContent = "Copy To";
                l_cue.IsDropPossible = true;
                break;
            case DragAndDropEffects.Move:
                l_cue.DragActionContent = "Link With";
                l_cue.IsDropPossible = true;
                break;
            default:
                l_cue.IsDropPossible = false;
                break;
        }
    }

    Now with the new version, I'm using the recommended DragDropManager and DragDropPayloadManager objects, I tried this:
    private void OnDragOver(object sender, System.Windows.Forms.DragEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
        if (options != null)
                {
                    var l_dragVisual = options.DragVisual as TreeViewDragVisual;
                    switch (effects)
                    {
                        case DragAndDropEffects.None:
                            options.DropAction = DropAction.None;
                            if (l_dragVisual != null)
                            {
                                l_dragVisual.IsDropPossible = false;
                                options.UpdateDragVisual();
                            }
                            break;
                        case DragAndDropEffects.Copy:
                            options.DropAction = DropAction.Delete;
                            if (l_dragVisual != null)
                            {
                                l_dragVisual.IsDropPossible = true;
                                options.UpdateDragVisual();
                                l_dragVisual.DropActionText = "Copy To";
                            }
                            break;
                        case DragAndDropEffects.Move:
                            options.DropAction = DropAction.Delete;
                            if (l_dragVisual != null)
                            {
                                l_dragVisual.IsDropPossible = true;
                                options.UpdateDragVisual();
                                l_dragVisual.DropActionText = "Link With";
                            }
                            break;
                    }
                }
    }

    Unfortunately, the options object is always null.
    Is there a way to change the TreeViewDragVisual object to give a feedback ?

    Best regards,
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 30 Jan 2014 Link to this post

    Hello Stéphane,

    Could you please confirm that you have set the TreeViewSettings.DragDropExecutionMode to "New"? Also you can checkout the following resources in which DragOver event is used for customization purposes in drag drop operation:
    However if that doesn't help could you please elaborate more on your scenario - do you set the e.Data in DragInitialize handler? Is it possible for you to send us more from your code or an isolated sample that we can better investigate ?

    Thank you in advance for your cooperation.

    Regards,
    Boris Penev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Stéphane
    Stéphane avatar
    3 posts
    Member since:
    Apr 2012

    Posted 30 Jan 2014 in reply to Boris Link to this post

    Hello Boris,

    Yes, I have set TreeViewSettings.DragDropExecutionMode to "New".
    My question is not about a drag and drop between 2 Wpf controls but from a RadTreeview (WPF) to a winforms control.
    I attached a full sample.
    As you can see in this sample I can drag a node from my treeview, if I drag it over the wpf listbox, the label (TreeViewDragVisual
    ) is changed, if I drag it over the WinForms label, the label is not updated.
    Rename the attached file to xxx.zip.

    Best regards,
  5. Boris
    Admin
    Boris avatar
    276 posts

    Posted 04 Feb 2014 Link to this post

    Hello Stéphane,

    DragDrop operation from WPF to Winforms control is not support out of the box by DragDropManager (which is used internally in the NEW DragDropExecution mode in RadTreeView).
    We used your project and made some changes in order to achieve the desired result. We created a private field options in the code-behind and we used it in DragInitialize event of the TreeView and DragOver event of the Winforms' ListBox:
    private TreeViewDragDropOptions options;

    private void OnDragInitialize(object sender, DragInitializeEventArgs e)
            {
                this.options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;

    void lb_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
            {
                if (this.options != null)
                {
                    options.DropAction = DropAction.Delete;
    ....

    The reason why the old RadDragAndDropManager class works is that it is static with a static property Options that could have been set from anywhere. Actually our workaround is similar to this approach.

    On the other hand we guess the Framework converts automatically the data from a WPF's DragDrop event to data in Winforms DragDrop event and that is why we cannot get it successfully with 
    DragDropPayloadManager.GetDataFromObject()
    We even tested with 
    (e.Data as System.Windows.Forms.DataObject).GetData(,)
    but this does not work.

    Please let us know if this helps you.

    Regards,
    Boris Penev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Stéphane
    Stéphane avatar
    3 posts
    Member since:
    Apr 2012

    Posted 05 Feb 2014 in reply to Boris Link to this post

    Hello Boris,

    yes this workaround is working, thanks for your feedback.
    I use a static class because this information is shared between several controls from different projects.

    Best regards,
Back to Top
UI for WPF is Visual Studio 2017 Ready