Solved

Drag-and-Drop multiple strings between listboxes

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 36
C# Problem Solving Execerscise 5 40
How to Get total minutes between two hours 4 26
bulid json format 3 17
Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now