E
emferrari
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.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
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.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