2011 Q2 - Drag and drop from ListView to RadTreeView, how to expand the node where the mouse is over?

4 posts, 0 answers
  1. Volkan
    Volkan avatar
    3 posts
    Member since:
    Jul 2010

    Posted 12 Aug 2011 Link to this post

    Hi, i drag and drop from a ListView (MS) to a RadTreeView

    But i need a function that if the mouse is while is dragging over a node it should be automaticly expand so that the user can browse the tree where he can drop the item.

    How can i archive that?

    Here are my codes:

    private void listView_Result_ItemDrag(object sender, ItemDragEventArgs e)
          {
              lblDragID.Text = listView_Result.SelectedItems[0].Tag.ToString();
              listView_Result.DoDragDrop(listView_Result.SelectedItems, DragDropEffects.Move);
          }


    private void TreeHome_DragDrop(object sender, DragEventArgs e)
         {
             try
             {
                 string x = lblDragID.Text;
                 Point p = System.Windows.Forms.Control.MousePosition;
                   
                 // Expand node if the mouse is over a one, and get the node id if the drop is finished (?)
                 MessageBox.Show(lblDragID.Text);
                 lblDragID.Text = "0";
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }

    ???

    And yea, another small question here :D
    How can i expand/open a node with just the id is stored in the tag field?

    Thank you for the help
    Volkan

  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 16 Aug 2011 Link to this post

    Hello Volkan,

    Thank you for writing.

    You can expand a hovered node by setting the Expanded property of RadTreeNode. Here is an example:
    Point p = System.Windows.Forms.Control.MousePosition;
    TreeNodeElement node = radTreeView1.ElementTree.GetElementAtPoint(p) as TreeNodeElement;
    if (node != null)
    {
        node.Data.Expanded = true;
    }

    In regards to your second question, you should iterate over the nodes and find the one matching the ID. Afterwards, set its Expanded property to expand it.

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    Regards,
    Stefan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Volkan
    Volkan avatar
    5 posts
    Member since:
    Jun 2011

    Posted 16 Aug 2011 Link to this post

    Thank you Stefan for your reply, i have 2 questions
    If i use the DragOver or the DragOverNode events i got a posisition, but no node is found at this position.

    And whats the difference between this 2 methods:
    TreeHome.GetNodeAt()
    TreeHome.ElementTree.GetElementAtPoint()

     

    private void TreeHome_DragOverNode(object sender, RadTreeViewDragCancelEventArgs e)
          {
              Point po = System.Windows.Forms.Control.MousePosition;
              TreeNodeElement node = TreeHome.ElementTree.GetElementAtPoint(po) as TreeNodeElement;
              if (node != null)
              {
                  node.Data.Expanded = true;
              }
          }

     

    private void TreeHome_DragOver(object sender, DragEventArgs e)
           {
               Point po = System.Windows.Forms.Control.MousePosition;
               TreeNodeElement node = TreeHome.ElementTree.GetElementAtPoint(po) as TreeNodeElement;
               if (node != null)
               {
                   node.Data.Expanded = true;
               }
           }

     

     

    I have bind this events on the treeview self(?)
    The second question is, how can i iterate trough all nodes?

    Thank you
    Volkan

  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 19 Aug 2011 Link to this post

    Hi Volkan,

    Thank you for writing back.

    I am getting straight to your questions:
    1. Both of these methods do the same thing - take the element at a certain point. 
    2. Iterating over nodes in RadTreeView can be achieved by iterating over the Nodes collection of the control. However, if you have hierarchical nodes structure, you will have to traverse the collection recursively (each node has its own Nodes collection).

    Additionally, I have implemented the scenario for drag and drop from ListView to RadTreeView in the attached solution. 

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    Regards,
    Stefan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top