ListBox To ListBox Drag Drop And Dataset?

Posted on 2009-05-19
Last Modified: 2012-06-27
I've found many good articles concerning ListBox drag-n-drop, but I'm still unsure how to update each ListBox's datasource. In this case each Listbox needs to connect to it's own dataset. Each datset will contain 4 columns, one of which is displayed in the ListBox. Upon drag-n-drop, the entire row needs transfered to the opposite dataset. I need to move data back-n-forth as well, not just one-way.

ListBox1 (displays only FirstLastName)  
ds1.tb1 [ID, FirstLastName, Mid, Bday, SS] (entire row moved to other dataset)

ListBox2 (displays only FirstLastName)  
ds2.tb2 [ID, FirstLastName, Mid, Bday, SS]
Question by:pointeman
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
LVL 12

Accepted Solution

wht1986 earned 500 total points
ID: 24427982
In the code below, I have 2 listboxes bound to 2 different datasets (but same schema)

To start with I fill one dataset with values from the database.

The code below shows how I can drag and drop items between the listboxes while moving the associated datarow from 1 dataset table to another.
namespace Win_Forms
    public partial class Form1 : Form
        public Form1()
        private void Form1_Load(object sender, EventArgs e)
        private void listBox1_DragDrop(object sender, DragEventArgs e)
            DataRow frow = (DataRow)(e.Data.GetData(e.Data.GetFormats()[0]));
        private void listBox2_DragDrop(object sender, DragEventArgs e)
            DataRow frow = (DataRow)(e.Data.GetData(e.Data.GetFormats()[0]));
        private void listBox1_MouseDown(object sender, MouseEventArgs e)
            if (listBox1.Items.Count == 0)
            int index = listBox1.IndexFromPoint(e.X, e.Y);
            DoDragDrop(ds1.Facilities[index], DragDropEffects.All);
        private void listBox2_MouseDown(object sender, MouseEventArgs e)
            if (listBox2.Items.Count == 0)
            int index = listBox2.IndexFromPoint(e.X, e.Y);
            DoDragDrop(ds2.Facilities[index], DragDropEffects.All);
        private void listBox1_DragOver(object sender, DragEventArgs e)
            e.Effect = DragDropEffects.All;
        private void listBox2_DragOver(object sender, DragEventArgs e)
            e.Effect = DragDropEffects.All;

Open in new window


Author Closing Comment

ID: 31583265
Excellent, thanks.........

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What Does This C# Code Block Do? 5 74
tableview is not updating 1 28
Amazon S3 .Net error 5 44
Adjust the codes 3 38
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

696 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