I have a list box and a tree image
Once my list is filled with box items, I want to pull them from the list by pulling the list (multiple or single) and they want to drop them into a node in the tree view.
If someone has a good example in C # which would be great.
After a while I have messed with drag / drop so I thought I I will write a quick sample. Basically, I have a form, a list box on the left and a treview on the right. Then I put a button on top when the button is clicked, then it only puts it in the list box for the next 10 days. It also offers tree view along with 2 parent nodes and two hair nodes. After this, you have to handle all later drag / drop events to make it work.
Public Partial Sections Form 1: Form {Public Form 1 () {InitializeComponent (); This.treeView1.AllowDrop = True; This.listBox1.AllowDrop = True; This.listBox1.MouseDown + = New MouseEventHandler (listBox1_MouseDown); This.listBox1.DragOver + = New DragEventHandler (listBox1_DragOver); This.treeView1.DragEnter + = New DragEventHandler (treeView1_DragEnter); This.treeView1.DragDrop + = New DragEventHandler (treeView1_DragDrop); } Private Zero Button 1_Click (Object Sender, EventArgs e) {this.PoupulateListBox (); This.PopulateTreeView (); } Private Zero populateListBox () {for (int i = 0; i & lt; = 10; i ++) {this.listBox1.Items.Add (DateTime.Now.AddDays (i)); }} Private zero populateTreeView () {for (int i = 1; i & lt; = 2; i ++) {tree node = new tree node ("node" + i); {Node.Nodes.Add ("subnode" + j) for (int j = 1; j & lt; = 2; j ++); } This.treeView1.Nodes.Add (node); }} Private Zero Tree View 1_DragDrop (Object Sender, DragEvent Argus E) {TreeNode Nodatoidprone = This Tree V 1. Gittnodaut (this. TreeView1.PointToClient (new point (E.X, E.I.I.)); If (nodododin == tap) {return; } If (nodeToDropIn.Level> 0) {nodeToDropIn = nodeToDropIn.Parent; } Object data = E. Data. Getadata (typefime); If (data == empty) {return; } NodeToDropIn.Nodes.Add (Data. ToString ()); This.listBox1.Items.Remove (data); } Private Zero ListBox 1_DragOver (Object Sender, DragEventArgs e) {e.ffect = DragDropEffects.Move; } Private Zero Tree View1_DragEnter (Object Sender, DragEventArgs e) {e.ffect = DragDropEffects.Move; } Private Zero ListBox 1_MouseDown (Object Sender, MouseEventArgs E) {this.listBox1.DoDragDrop (this.listBox1.SelectedItem, DragDropEffects.Move); }}
Comments
Post a Comment