Solved

Drag-and-Drop multiple strings between listboxes

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

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 aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

737 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