473,621 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drag and Drop using two TreeViews

Hi everybody

I have two treeviews, one of them is only to receive items dragged from
the treeview1. I want to know how to drag a full node information to
the treeview2. I know how to do that only in a single node operation.

Here is my current code:

private void trv_Directories _ItemDrag(objec t sender, ItemDragEventAr gs
e)
{
string strItem = e.Item.ToString ();

// Start the Drag Operation
DoDragDrop(strI tem, DragDropEffects .Copy);
}

private void trv_Directories _DragEnter(obje ct sender, DragEventArgs e)
{
// Determine if we are dragging something, if we are, set the effect
if (e.Data.GetData Present(DataFor mats.Text))
e.Effect = DragDropEffects .Copy;
else
e.Effect = DragDropEffects .None;
}

private void trv_Selection_D ragEnter(object sender, DragEventArgs e)
{
// Handle the Drag effect when the listbox is entered
if (e.Data.GetData Present(DataFor mats.Text))
e.Effect = DragDropEffects .Copy;
else
e.Effect = DragDropEffects .None;
}

private void trv_Selection_D ragDrop(object sender, DragEventArgs e)
{
string dummy = "";
bool itemFound = false;

// Get the string from the data that was dragged
string s = (string)e.Data. GetData(dummy.G etType());
s = s.Substring(s.I ndexOf(":") + 1).Trim();
Position.X = e.X;
Position.Y = e.Y;

Position = trv_Selection.P ointToClient(Po sition);

// Checks if the item to be dropped is new for the list
for(int i=0; i<trv_Selection .Nodes.Count; i++)
{
// If finds the item on the list don't do nothing
if(trv_Selectio n.Nodes[i].Text == s)
{
itemFound = true;
break;
}
else
itemFound = false;
}

// If the item wasn't found on the list, add it.
if(!itemFound)
// Drop the string in the listbox
trv_Selection.N odes.Add(s);
}

Any information will be appreciated!

Thanks!

Eduardo

Nov 17 '05 #1
1 3496
http://www.eggheadcafe.com/articles/...atabinding.asp

Learn an additional method for databinding a DataSet to a windows forms .NET
TreeView control. Learn how to drag and drop nodes on the same TreeView
control as well as drag and drop nodes across multiple TreeView controls
while maintaining the data bound relationship with the source and target
TreeView's DataSet.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

<em*******@gmai l.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Hi everybody

I have two treeviews, one of them is only to receive items dragged from
the treeview1. I want to know how to drag a full node information to
the treeview2. I know how to do that only in a single node operation.

Here is my current code:

private void trv_Directories _ItemDrag(objec t sender, ItemDragEventAr gs
e)
{
string strItem = e.Item.ToString ();

// Start the Drag Operation
DoDragDrop(strI tem, DragDropEffects .Copy);
}

private void trv_Directories _DragEnter(obje ct sender, DragEventArgs e)
{
// Determine if we are dragging something, if we are, set the effect
if (e.Data.GetData Present(DataFor mats.Text))
e.Effect = DragDropEffects .Copy;
else
e.Effect = DragDropEffects .None;
}

private void trv_Selection_D ragEnter(object sender, DragEventArgs e)
{
// Handle the Drag effect when the listbox is entered
if (e.Data.GetData Present(DataFor mats.Text))
e.Effect = DragDropEffects .Copy;
else
e.Effect = DragDropEffects .None;
}

private void trv_Selection_D ragDrop(object sender, DragEventArgs e)
{
string dummy = "";
bool itemFound = false;

// Get the string from the data that was dragged
string s = (string)e.Data. GetData(dummy.G etType());
s = s.Substring(s.I ndexOf(":") + 1).Trim();
Position.X = e.X;
Position.Y = e.Y;

Position = trv_Selection.P ointToClient(Po sition);

// Checks if the item to be dropped is new for the list
for(int i=0; i<trv_Selection .Nodes.Count; i++)
{
// If finds the item on the list don't do nothing
if(trv_Selectio n.Nodes[i].Text == s)
{
itemFound = true;
break;
}
else
itemFound = false;
}

// If the item wasn't found on the list, add it.
if(!itemFound)
// Drop the string in the listbox
trv_Selection.N odes.Add(s);
}

Any information will be appreciated!

Thanks!

Eduardo

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4011
by: #Hai | last post by:
Hi, I have a TreeView control with hierarchy: A | - B // source | - C D // dest | - E Whenever draging B in to D, Item B is removed and B is added into D node. To implement this task, I ,firstly, write a simple MouseDown event to start
0
1199
by: Sam | last post by:
Hi there, I have a problem with dragging and dropping a node from one tree to another. I can drag and drop a node in T1 but not from T2 to T1. I have AllowDrop of T1 = true but for T2 = false since I want to allow dropping to T1 only. What happens is that when I drag a node in T1 over nodes in T1, this works fine and the sign of the drag is there, and I can drop it fine. On the other hand, when I drag a node from T2 into T1, the sign looks...
0
1107
by: Gurudev | last post by:
Is it possible to create an explorer style drag and drop for treeviews in C# i.e. the selected node text appears and moves along with the cursor while dragging thanks in advance -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Gurudev Software Engineer, NetKraft,
0
2413
by: Norbert Heidbüchel | last post by:
Hi all, I have read a lot of postings and web pages about drag and drop and treeviews, but could not find an answer to my problem. Sorry, if I missed something. I am trying to drag and drop treenodes defined by myself and don't understand, how to get the nodes data in the dragdrop event. I'm not very experienced in .NET and for sure there is a simple solution. I've written a short sample program, based on well known examples,
0
2860
by: Yavuz Bogazci | last post by:
Hi, i have build a form with a listbox and the function that he user can drag and drop files from the windows explorer in this listbox. this works for me when i start it on my localmachine. But when i put my Apps .exe file on my WebServers WWWROOT directory and call it from the internet explorer. the application starts with the following error message.
1
2298
by: Terry Olsen | last post by:
My first time using TreeViews. I have TreeView1 set up to display my directory structure just like Windows Explorer. I can drag & drop files and folders over to TreeView2. I can re-arrange the structure in TreeView2 (putting files in different folders and such...like you do when you create a structure for burning a CD). I have two questions. 1. How can I remember the full path from TreeView1 (when it comes time to actually do...
1
1866
by: pooja | last post by:
i need to implement drag and drop in treeview in VB. Kindly help. My treeview contains activities maintained using XML Files. Hopefully, Thanks.
1
2305
by: SteveDouglas | last post by:
Hi all, I am currently writing an application in VB.NET that has a lot of controls (treeviews/listviews/labels and so forth) that represent "things" that need to be draggable from place to place, including between controls and windows. In the past when I've implemented Drag and Drop in other projects, I've always passed the item being dragged (for example the listviewitem or the treenode) to the DoDragDrop and then retrieved it in the...
1
1755
by: jotaefe | last post by:
Hi there, Anybody knows if it is possible to highlight nodes on a treeview (over) on a drag and drop operation from a different treeview? The two treeviews are in the same Windows form. Your responses are very much appreciate.
0
8597
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8306
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8457
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7127
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5554
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4065
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2587
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1460
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.