This is a migrated thread and some comments may be shown as answers.

Running form as Dialog from Treeview DragEnded event stuck sometimes

3 Answers 25 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Maximo
Top achievements
Rank 1
Maximo asked on 04 May 2018, 04:22 PM

I'm using two RadTreeView to Drag and Drop Nodes from Right to Left. When "Node 1" is Drag from Right and Drop to Left RadTreeView a Dialog is shown.
If I Drag and Drop other Node before "Node 1" the Dialog stuck and I cannot write on the TexBoxes.

How can I solve this issue?

Main Form 

https://i.stack.imgur.com/Qf1QM.png

public partial class Main : RadForm
{
    public Main()
    {
        InitializeComponent();
    }
 
    private void RightRadTreeView_DragEnded(object sender, RadTreeViewDragEventArgs e)
    {
        if (e.Node.Text == "Node 1")
        {
            new RadForm1().ShowDialog();
        }
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
        //Right
        this.RightRadTreeView.Nodes.Add(new RadTreeNode { Text = "Node 1" });
        this.RightRadTreeView.Nodes.Add(new RadTreeNode { Text = "Node 2" });
        this.RightRadTreeView.Nodes.Add(new RadTreeNode { Text = "Node 3" });
        this.RightRadTreeView.Nodes.Add(new RadTreeNode { Text = "Node 4" });
    }
}

 

Dialog Form

https://i.stack.imgur.com/hH7Ln.png

 

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 07 May 2018, 11:07 AM
Hi Maximo,

Thank you for writing.

The preview hint is being displayed in its own window and when you show the form with the ShowDialog method it will block its execution. In order to accomplish your task, you will need to wait for the entire drag operation to complete. Drag and drop in the tree are managed by the TreeViewDragDropService class: https://docs.telerik.com/devtools/winforms/treeview/drag-and-drop/treeviewdragdropservice. A suitable place is the event handler of the Stopped event of the service: 
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    public RadForm1()
    {
        InitializeComponent();
         
        this.radTreeView1.AllowDragDrop = true;
        this.radTreeView2.AllowDragDrop = true;
        this.radTreeView1.TreeViewElement.DragDropService.Stopped += DragDropService_Stopped;
    }
 
    private void DragDropService_Stopped(object sender, EventArgs e)
    {
        RadForm2 f = new RadForm2();
        f.ShowDialog();
        f.Dispose();
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
 
        this.radTreeView1.Nodes.Add(new RadTreeNode { Text = "Node 1" });
        this.radTreeView1.Nodes.Add(new RadTreeNode { Text = "Node 2" });
        this.radTreeView1.Nodes.Add(new RadTreeNode { Text = "Node 3" });
        this.radTreeView1.Nodes.Add(new RadTreeNode { Text = "Node 4" });
    }
}

I hope this helps. Let me know if you have other questions.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Maximo
Top achievements
Rank 1
answered on 07 May 2018, 01:05 PM

Hello Hristo,

Thanks for your response. This solve my issue partially. But generate two new issues, using DragDropService:

  1. I haven't found how to validate when e.Node.Text == "Node 1"
  2. DragDropService_Stopped fires when I click on node. I was searching into DragDropService_Starting but not found how to prevent Dialog show only when e.Node.Text == "Node 1"is dropped on the left side.
0
Accepted
Hristo
Telerik team
answered on 08 May 2018, 08:50 AM
Hello Maximo,

You can handle the PreviewDragDrop event of the service and raise a flag for the first node. Then in the Stopped event of the service depending on the flag, you can decide whether to show the dialog: 
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    public RadForm1()
    {
        InitializeComponent();
         
        this.radTreeView1.AllowDragDrop = true;
        this.radTreeView2.AllowDragDrop = true;
 
        this.radTreeView1.TreeViewElement.DragDropService.PreviewDragDrop += DragDropService_PreviewDragDrop;
        this.radTreeView1.TreeViewElement.DragDropService.Stopped += DragDropService_Stopped;
    }
 
    bool showDialog;
    private void DragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
    {
        TreeNodeElement nodeElement = e.DragInstance as TreeNodeElement;
        if (nodeElement.Data.Text == "Node 1")
        {
            this.showDialog = true;
        }
    }
 
    private void DragDropService_Stopped(object sender, EventArgs e)
    {
        if (this.showDialog)
        {
            this.showDialog = false;
 
            RadForm2 f = new RadForm2();
            f.ShowDialog();
            f.Dispose();
        }
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
 
        this.radTreeView1.Nodes.Add(new RadTreeNode { Text = "Node 1" });
        this.radTreeView1.Nodes.Add(new RadTreeNode { Text = "Node 2" });
        this.radTreeView1.Nodes.Add(new RadTreeNode { Text = "Node 3" });
        this.radTreeView1.Nodes.Add(new RadTreeNode { Text = "Node 4" });
    }
}

The Stopped event should fire only if a drag operation has been started and then ended. It should not fire when clicking on the nodes. In case you keep experiencing an issue please attach a short video showing the result on your end.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Treeview
Asked by
Maximo
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Maximo
Top achievements
Rank 1
Share this question
or