473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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(object sender, ItemDragEventArgs
e)
{
string strItem = e.Item.ToString();

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

private void trv_Directories_DragEnter(object sender, DragEventArgs e)
{
// Determine if we are dragging something, if we are, set the effect
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void trv_Selection_DragEnter(object sender, DragEventArgs e)
{
// Handle the Drag effect when the listbox is entered
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void trv_Selection_DragDrop(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.GetType());
s = s.Substring(s.IndexOf(":") + 1).Trim();
Position.X = e.X;
Position.Y = e.Y;

Position = trv_Selection.PointToClient(Position);

// 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_Selection.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.Nodes.Add(s);
}

Any information will be appreciated!

Thanks!

Eduardo

Nov 17 '05 #1
1 3467
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*******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.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(object sender, ItemDragEventArgs
e)
{
string strItem = e.Item.ToString();

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

private void trv_Directories_DragEnter(object sender, DragEventArgs e)
{
// Determine if we are dragging something, if we are, set the effect
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void trv_Selection_DragEnter(object sender, DragEventArgs e)
{
// Handle the Drag effect when the listbox is entered
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void trv_Selection_DragDrop(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.GetType());
s = s.Substring(s.IndexOf(":") + 1).Trim();
Position.X = e.X;
Position.Y = e.Y;

Position = trv_Selection.PointToClient(Position);

// 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_Selection.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.Nodes.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
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...
0
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...
0
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 --...
0
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...
0
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. ...
1
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...
1
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
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,...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.