Running form as Dialog from Treeview DragEnded event stuck sometimes

4 posts, 1 answers
  1. Maximo
    Maximo avatar
    2 posts
    Member since:
    May 2018

    Posted 04 May 2018 Link to this post

    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

     

  2. Hristo
    Admin
    Hristo avatar
    1508 posts

    Posted 07 May 2018 Link to this post

    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.
  3. Maximo
    Maximo avatar
    2 posts
    Member since:
    May 2018

    Posted 07 May 2018 in reply to Hristo Link to this post

    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.
  4. Answer
    Hristo
    Admin
    Hristo avatar
    1508 posts

    Posted 08 May 2018 Link to this post

    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.
Back to Top