树控件内容拖拽到文本框
一个简单的例子,供大家参考。
View Code
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private TreeNode NodeMouseOn = null; private void treeView1_ItemDrag(object sender, ItemDragEventArgs e) { ArrayList al = new ArrayList(); this.NodeMouseOn = (TreeNode)e.Item; al.Add(NodeMouseOn); DoDragDrop(al, DragDropEffects.Copy); ///////////////////////// //TreeNode tnNew = null; //string tnName; //tnName = dr["ItemClassName"].ToString(); //tnNew = tnParent.Nodes.Add(tnName); //tnNew.ta.Tag = dr["ItemClassID"].ToString(); } private void textBox1_DragDrop(object sender, DragEventArgs e) { ArrayList al = new ArrayList(); ArrayList s = (ArrayList)e.Data.GetData(al.GetType()); this.textBox1.Text += ((TreeNode)s[0]).Text; } private void textBox1_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Copy; } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); } private void Form1_Load(object sender, EventArgs e) { } }
源码点击下载
踏踏实实做人.