关于TreeView的拖放事件,下面是我的代码,我想问一下为什么Button就转换成功了,而TreeView就失败了?
privatevoidtreeView1_ItemDrag(objectsender,ItemDragEventArgse){treeView1.DoDragDrop(t...
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
treeView1.DoDragDrop(treeView1,DragDropEffects.Move);
}
private void treeView2_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
TreeNode myNode = null;
if (e.Data.GetDataPresent(typeof(TreeNode)))
{
myNode = (TreeNode)(e.Data.GetData(typeof(TreeNode)));
}
else if (e.Data.GetDataPresent(typeof(Button)))
{
this.textBox1.Text = "button";
}
else
{
MessageBox.Show("error");
}
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(TreeNode)))
e.Effect = DragDropEffects.Move;
else if (e.Data.GetDataPresent(typeof(Button)))
{
e.Effect = DragDropEffects.All;
}
else
e.Effect = DragDropEffects.None;
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button==MouseButtons.Left)
{
button1.DoDragDrop(button1, DragDropEffects.Move);
}
} 展开
{
treeView1.DoDragDrop(treeView1,DragDropEffects.Move);
}
private void treeView2_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
TreeNode myNode = null;
if (e.Data.GetDataPresent(typeof(TreeNode)))
{
myNode = (TreeNode)(e.Data.GetData(typeof(TreeNode)));
}
else if (e.Data.GetDataPresent(typeof(Button)))
{
this.textBox1.Text = "button";
}
else
{
MessageBox.Show("error");
}
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(TreeNode)))
e.Effect = DragDropEffects.Move;
else if (e.Data.GetDataPresent(typeof(Button)))
{
e.Effect = DragDropEffects.All;
}
else
e.Effect = DragDropEffects.None;
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button==MouseButtons.Left)
{
button1.DoDragDrop(button1, DragDropEffects.Move);
}
} 展开
3个回答
展开全部
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
TreeNode tn = e.Item as TreeNode;
if ((e.Button == MouseButtons.Left) && (tn != null) && (tn.Parent != null)) //根节点不允许拖放操作。
{
this.treeView1.DoDragDrop(tn, DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link);
}
}
{
TreeNode tn = e.Item as TreeNode;
if ((e.Button == MouseButtons.Left) && (tn != null) && (tn.Parent != null)) //根节点不允许拖放操作。
{
this.treeView1.DoDragDrop(tn, DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link);
}
}
追问
谢了。 还有就是 it = (ListViewItem)e.Data.GetData(typeof(ListViewItem)); 直接绑定ListView为什么不显示信息?
追答
// 把ListView的ItemDrag响应处理DoDragDrop写成这样试试
listView1.DoDragDrop(e.Item, DragDropEffects.Move);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询