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

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

3 Answers 89 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Volkan
Top achievements
Rank 1
Volkan asked on 12 Aug 2011, 10:52 PM
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

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Aug 2011, 03:08 PM
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 >>

0
Volkan
Top achievements
Rank 1
answered on 16 Aug 2011, 04:02 PM

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

0
Stefan
Telerik team
answered on 19 Aug 2011, 08:21 AM
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 >>

Tags
Treeview
Asked by
Volkan
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Volkan
Top achievements
Rank 1
Share this question
or