?
Solved

Drag-and-Drop multiple strings between listboxes

Posted on 2006-06-14
4
Medium Priority
?
1,296 Views
Last Modified: 2008-01-09
I need some help to implement the drag-and-drop related methods below. The idea is to select a set of items in one listbox and drag them all in one go to the other listbox. It shoud work the same way in both directions.


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace DragDropListBoxTest
{
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.ListBox listBox1;
            private System.Windows.Forms.ListBox listBox2;

            private System.ComponentModel.Container components = null;

            public Form1()
            {
                  InitializeComponent();
            }

            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.listBox1 = new System.Windows.Forms.ListBox();
                  this.listBox2 = new System.Windows.Forms.ListBox();
                  this.SuspendLayout();
                  //
                  // listBox1
                  //
                  this.listBox1.AllowDrop = true;
                  this.listBox1.Items.AddRange(new object[] {
                                                                                      "First item",
                                                                                      "Second item",
                                                                                      "Third item"});
                  this.listBox1.Location = new System.Drawing.Point(16, 16);
                  this.listBox1.Name = "listBox1";
                  this.listBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
                  this.listBox1.Size = new System.Drawing.Size(120, 95);
                  this.listBox1.TabIndex = 0;
                  this.listBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listBox1_MouseDown);
                  this.listBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listBox1_DragDrop);
                  this.listBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.listBox1_DragEnter);
                  //
                  // listBox2
                  //
                  this.listBox2.AllowDrop = true;
                  this.listBox2.Location = new System.Drawing.Point(152, 16);
                  this.listBox2.Name = "listBox2";
                  this.listBox2.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
                  this.listBox2.Size = new System.Drawing.Size(120, 95);
                  this.listBox2.TabIndex = 1;
                  this.listBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listBox2_MouseDown);
                  this.listBox2.DragDrop += new System.Windows.Forms.DragEventHandler(this.listBox2_DragDrop);
                  this.listBox2.DragEnter += new System.Windows.Forms.DragEventHandler(this.listBox2_DragEnter);
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(288, 126);
                  this.Controls.Add(this.listBox2);
                  this.Controls.Add(this.listBox1);
                  this.Name = "Form1";
                  this.Text = "DragDropListBoxTest";
                  this.ResumeLayout(false);

            }
            #endregion

            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
            {

            }

            private void listBox2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
            {

            }

            private void listBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
            {

            }

            private void listBox2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
            {

            }

            private void listBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
            {
            
            }

            private void listBox2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
            {
            
            }
      }
}
0
Comment
Question by:liljegren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
Anandavally_P earned 1000 total points
ID: 16909323
Try this link
http://www.codeproject.com/cs/combobox/LarryDragAndDrop.asp

Thanks
Anandavally Perumal

0
 

Author Comment

by:liljegren
ID: 16930692
Thank you. Sorry I haven't been able to evaluate this reply yet. I'll look into this more again in a few days. Then I'll post here again.
0
 

Author Comment

by:liljegren
ID: 17078447
Yes, I'm sorry. I forgot about this. I'll accept Anandavally_P's answer now.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question