468,272 Members | 2,171 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

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 3113
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by #Hai | last post: by
reply views Thread by Sam | last post: by
reply views Thread by Yavuz Bogazci | last post: by
1 post views Thread by Terry Olsen | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.