Solved

Drag-and-Drop multiple strings between listboxes

Posted on 2006-06-14
4
1,294 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 250 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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