![]() |
DragDrop in TreeView
1 Attachment(s)
When I started on Drag and Drop in C# I could not find much on the net and so I have decided to tackle the problem here. First follow the steps to see the working sample.
1. Create a new C sharp windows application. Rename Form1 to a suitable name. I would refer it as TestForm 2. Add a treeview control with some dummy nodes randomly. 3. Extract DragDropTreeView.cs from the attached zipped file and copy DragDropTreeView.cs to the project directory. 4. Add DragDropTreeView.cs as an Existing item to the project 5. Go to TestForm.Designer.cs 6. Add Code: CSHARP
7. Now find Code: CSHARP
Code: CSHARP
Code: CSHARP
Code: CSHARP
Now the question comes is what is in DragDropTreeView.cs so that it behaves in such a fashion. First thing that it does is sets the property AllowDrop of the DragDropTreeView to true so that we can handle the drag drop events for the TreeView control.Next it overrides the 3 basic or you can say minimal drag drop event handler of TreeView. i.e. OnDragDrop, OnDragOver, OnItemDragCode: CSHARP
Code: CSHARP
Code: CSHARP
|
Re: DragDrop in TreeView
Dear Sir,
I have seen your code regarding drag and drop operations in a treeview.It is adding as a child at a dragged position.But i need to move nodes up and down with in a same level(drag and dropping of nodes at required position at a same level). I need this code very urgent.I will be waiting for your reply...... Thanking You Sir........ :) |
Re: DragDrop in TreeView
Dear Sir,
I have seen your code regarding drag and drop operations in a treeview.It is adding as a child at a dragged position.But i need to move nodes up and down with in a same level(drag and dropping of nodes at required position at a same level). I need this code very urgent.I will be waiting for your reply...... Thanking You Sir........ |
Re: DragDrop in TreeView
Do you mean you need to add the node as its siblings to the node where the drop has taken place.
If thats the case modify OnDragDrop to find the parent node of the DestinationNode and add it to the child of the parent node. |
Re: DragDrop in TreeView
Dear Sir,
I am very thankful for giving the suggestion. My problem is to add the dragged node as a next node(immediate sibling),at dropping position which are at same level. OR I need code,such that when we a right-click on a node,the context menu has controls for moving the selected node up and down. I will be waiting for your esteemed reply........ Thanking You Sir........ |
Re: DragDrop in TreeView
--------------------------------------------------------------------------------
Dear Sir, I am very thankful for giving the suggestion. My problem is to add the dragged node as a next node(immediate sibling),at dropping position which are at same level with in a single tree. OR I need code,such that when we a right-click on a node,the context menu has controls for moving the selected node up and down with in a single tree. I will be waiting for your esteemed reply........ Thanking You Sir........ |
Re: DragDrop in TreeView
Quote:
Quote:
|
Re: DragDrop in TreeView
Dear Sir,
With help of your advice ,I can move the node.But it is adding as a last child to the parent. I want to place the dragged node at dropping position itself. I want help on this context. Please kindly reply me. I will be waiting for your reply....... Thanking You Sir......... |
Re: DragDrop in TreeView
--------------------------------------------------------------------------------
Dear Sir, With help of your advice ,I can move the node.But it is adding as a last child to the parent. I want to place the dragged node at dropping position itself. I want help on this context. Please kindly reply me. I will be waiting for your reply....... Thanking You Sir......... |
Re: DragDrop in TreeView
You need to move the node to the needed position as Add does not have any overloaded which can add a specified position of the parent node.
|
Re: DragDrop in TreeView
Is it possible to show the node in a color currently the mouse over on it
|
Re: DragDrop in TreeView
Quote:
|
Re: DragDrop in TreeView
Dear Sir,
With your help,I can able to place the nodes at required positions.But I can't save the file.How can I save it?If I saves it 80% of my work will be complete. Please kindly help me on this context..... I will be waiting for your reply... Thanking You Siir......... |
Re: DragDrop in TreeView
Which file you are trying to save??
|
Re: DragDrop in TreeView
Dear Sir,
Actually I am working on XML File.I am representing an XML File in a treeview.After implementing required operatons(moving of nodes) ,eventhough I am giving a statement to save the file,the changes are not appearing in the original file. And one more thing is ,I am not able to scroll treeview while performing Drag And Drop Operations. KIndly help me on these two things....... Waiting for your reply........ Thanking You Sir........... |
Re: DragDrop in TreeView
You need to provide some more details about the xml file so that we can understand how you are reading/writing and why the changes are not happening.
Regarding scrolling while you are dragging it should work with the mouse and not with the mouse scroll as with any other normal window/controls. |
Re: DragDrop in TreeView
Dear Sir,
I am moving moving the nodes of an xml file in a treeview to the desired positions.I can move nodes in a treeview to a desired position.These changes(new positions for nodes) can be seen in a treeview.But even though I am saving the file after moving the nodes,I am not able to see those changes,when we load the file next time. I am not understanding regarding of scrolling. Waiting for your reply.................. Thanking You Sir............ |
Re: DragDrop in TreeView
Regarding scrolling it should be behaving as any other normal window tree view does as we dont handle or interrupt anything in the tree view.
|
Re: DragDrop in TreeView
Dear Sir,
I am moving moving the nodes of an xml file in a treeview to the desired positions.I can move nodes in a treeview to a desired position.These changes(new positions for nodes) can be seen in a treeview.But even though I am saving the file after moving the nodes,I am not able to see those changes,when we load the file next time. Waiting for your reply.................. Thanking You Sir............ |
Re: DragDrop in TreeView
Dear Sir,
Can I implement autoscrolling in the treeview which is presented by you?If so how can I? |
Re: DragDrop in TreeView
Quote:
|
Re: DragDrop in TreeView
Dear Sir,
I want attach your code in my class itself,where I have performed some other functions.To do so,what are the things to be done? |
Re: DragDrop in TreeView
Quote:
|
Re: DragDrop in TreeView
Dear Sir,
Thanks for the help........... |
Re: DragDrop in TreeView
Quote:
|
Re: DragDrop in TreeView
Dear Sir,
I have one more problem.When a mouse moves on node ,how can I differentiate that node from other nodes?If so,how can I do it? |
Re: DragDrop in TreeView
Change the font of the node to something else.
|
Re: DragDrop in TreeView
Deat Sir,
Whether we need to change the font of nodes in Mouse_Move Event? |
Re: DragDrop in TreeView
It depends on your requirement.
|
Re: DragDrop in TreeView
Dear Sir,
Actually i want to show a node in color whenever a mouse moves over it.How can I do that? |
Re: DragDrop in TreeView
change the font of nodes in Mouse_Move Event
|
Re: DragDrop in TreeView
Dear Sir,
Thanks for the help............... |
Re: DragDrop in TreeView
Dear Sir,
When I write code in mouse move event,it showing error . here is the error Object reference not set to an instance of an object. Use the new keyword to create an object instance What to do? |
Re: DragDrop in TreeView
Please post your specific query as new thread as its not related to drag drop in tree view.
|
| All times are GMT +5.5. The time now is 21:18. |