Solved

ListBox Drag and Drop Property

Posted on 2010-08-16
21
1,003 Views
Last Modified: 2013-12-17
Experts
I want to drag and drop from one list box to another listbox.
Please see image attached and please advise me.
Thanking you,
Anindya
error.JPG
0
Comment
Question by:ANINDYA
  • 9
  • 6
  • 2
  • +4
21 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 33451646
0
 
LVL 4

Expert Comment

by:Sarika30
ID: 33451739
0
 
LVL 27

Expert Comment

by:nmarun
ID: 33451752
0
 
LVL 4

Expert Comment

by:Audhi203
ID: 33451772
0
 
LVL 4

Expert Comment

by:Audhi203
ID: 33451775
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 33451880
Try This one :

ASPX Code:    Email Message:  <asp:TextBox ID="txtMsg" runat="server" TextMode="MultiLine" Rows="10" Columns="50"   onclick="storeCur(this);" onkeyup="storeCur(this);" onselect="storeCur(this);"></asp:TextBox>                                List Values:<asp:ListBox ID="lstParameter" runat="server"    DataTextField="db_Values" DataValueField="db_Names" onmousedown="d = new drag(this)"onmouseup="d.drop(this.form.txtMsg)" onmouseout="if (typeof d != 'undefined') d.setIndex()"> </asp:ListBox>

Javascript :

<script language="javascript" type="text/javascript">  
function storeCur(txtMsg)               {                   if (txtMsg.createTextRange)                      txtMsg.caretPos = document.selection.createRange().duplicate();               }                function drag(objSource)                 {               this.select = objSource;             }                function drag.prototype.drop(objDest)                 {                if (!this.dragStart) return;                this.dest = objDest;      var pt=this.option.cloneNode(true);                   if (objDest.createTextRange && objDest.caretPos)                      {                                                            var caretPos = objDest.caretPos;                               if(caretPos.text.charAt(caretPos.text.length - 1) == '')                               {                                                                       caretPos.text =  pt.value;                               }                                   }        function drag.prototype.setIndex()         {         var i = this.select.selectedIndex;         window.status="selectedIndex = "+i;         if (i==-1) return;         this.option = this.select.options[i];         this.dragStart=true;        }   if (myField.selectionStart || myField.selectionStart == ‘0')    {       var startPos = myField.selectionStart;       var endPos = myField.selectionEnd;      myField.value = myField.value.substring(0, startPos)+ myValue    + myField.value.substring(endPos, myField.value.length);    }   else    {   myField.value += myValue;   }   }          
</script>


http://www.dotnetfunda.com/articles/article272.aspx
0
 
LVL 14

Expert Comment

by:systan
ID: 33452108
My Listbox1 to Listbox2 to Listbox1, vice versa.
//Put this code in your DragDrop Events in Listbox1 and Listbox2

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

{

	ListViewItem myItem = default(ListViewItem);

	ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");

	foreach (ListViewItem I in myItems) {

		myItem = new ListViewItem();

		myItem.Text = I.Text;

		myItem.ImageIndex = I.ImageIndex;

		if (sender.finditemwithtext(I.Text) == null) {

			sender.items.@add(myItem);

		}

	}

	if (sender.Name == myItems(0).ListView.Name)

		return;

	if (object.ReferenceEquals(sender, ListView1)) {

		ListView2.Items.Remove(ListView2.SelectedItems.Item(0));

	} else {

		ListView1.Items.Remove(ListView1.SelectedItems.Item(0));

	}

}





//Put this code in your DragEnter Events in Listbox1 and Listbox2

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

{

	ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");

	if (sender.Name == myItems(0).ListView.Name)

		return;

	if (e.Data.GetDataPresent("System.Windows.Forms.ListViewItem()")) {

		e.Effect = DragDropEffects.Move;

	} else {

		e.Effect = DragDropEffects.None;

	}

}





That's all, unless you want an events of mouse_click's

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 33452173
Oh, sorry for the code, actually it runs on vb.net, and now converted to c# from developer fusion, but errors come out.
Here's the vb.net code;

//Put this code in your DragDrop Events in Listbox1 and Listbox2

Private Sub ListView_DragDrop(ByVal sender As Object, ByVal e As _

    System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop, ListView2.DragDrop

        Dim myItem As ListViewItem

        Dim myItems() As ListViewItem = e.Data.GetData("System.Windows.Forms.ListViewItem()")

        For Each I As ListViewItem In myItems

            myItem = New ListViewItem

            myItem.Text = I.Text

            myItem.ImageIndex = I.ImageIndex

            If sender.finditemwithtext(I.Text) Is Nothing Then

                sender.items.add(myItem)

            End If

        Next

        If sender.Name = myItems(0).ListView.Name Then Exit Sub

        If sender Is ListView1 Then

            ListView2.Items.Remove(ListView2.SelectedItems.Item(0))

        Else

            ListView1.Items.Remove(ListView1.SelectedItems.Item(0))

        End If

    End Sub







//Put this code in your DragEnter Events in Listbox1 and Listbox2

Private Sub ListView_DragEnter(ByVal sender As Object, ByVal e As _

    System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter, ListView2.DragEnter

        Dim myItems() As ListViewItem = e.Data.GetData("System.Windows.Forms.ListViewItem()")

        If sender.Name = myItems(0).ListView.Name Then Exit Sub

        If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem()") Then

            e.Effect = DragDropEffects.Move

        Else

            e.Effect = DragDropEffects.None

        End If

    End Sub

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 33452264
Oh, it's a Listbox, Im sorry again, I've read it, but I'm thinking of a Listview
0
 

Author Comment

by:ANINDYA
ID: 33452306
Expert Systan
Please see the code it is showing huge errors.
will you please see why so.

thanking you
anindya



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace oppurtunity
{
    public partial class Form_TrainnerDetails : Form
    {
        private int indexOfItemUnderMouseToDrop;
        public Form_TrainnerDetails()
        {
            InitializeComponent();
           // this.listBox1.DragDrop += new
           //System.Windows.Forms.DragEventHandler(this.listBox1_DragDrop);
           // this.listBox1.DragEnter += new
           //            System.Windows.Forms.DragEventHandler(this.listBox1_DragEnter);

        }
        Class_ConnectionString connectionstring = new Class_ConnectionString();

        private void button1_Click(object sender, EventArgs e)
        {
            Form2Name f2n = new Form2Name();
            f2n.ShowDialog();
        }
        private void FormExperiment_Load(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(connectionstring.ToString()))
            {
                string query = "select distinct(mainTech) from Table_Technology";
                using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
                {
                    DataSet ds = new DataSet();
                    ad.Fill(ds, "Table_Technology");
                    comboBox1.DataSource = ds.Tables[0];
                    comboBox1.DisplayMember = "mainTech";
                    comboBox1.ValueMember = "mainTech";
                }
            }
        }
       

        private void Form_TrainnerDetails_Load(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(connectionstring.Connection))
            {
                string query = "select distinct(mainTech) from Table_Technology";
                using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
                {
                    DataSet ds = new DataSet();
                    ad.Fill(ds, "Table_Technology");
                    comboBox3.DataSource = ds.Tables[0];
                    comboBox3.DisplayMember = "mainTech";
                    comboBox3.ValueMember = "mainTech";
                }
            }
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            Int32 id = 0;
            using (SqlConnection con = new SqlConnection(connectionstring.Connection))
            {
                string query = "select TechID from Table_Technology where mainTech='" + comboBox3.Text + "' ";
                using (SqlCommand ad = new SqlCommand(query, con))
                {

                    //DataSet ds1 = new DataSet();
                    //ad.Fill(ds1, "Table_Technology");
                    //comboBox2.DataSource = ds1.Tables[0];
                    //comboBox2.DisplayMember = "SubTech";
                    //comboBox2.ValueMember = "SubTech";
                    con.Open();
                    SqlDataReader reader = ad.ExecuteReader();
                    while(reader.Read())
                    {
                        id=Convert.ToInt32(string.Format("{0}",reader[0]));
                    }
                }
            }

            using (SqlConnection con = new SqlConnection(connectionstring.Connection))
            {
                string query = "select SubTech from Table_SubTech where TechID='"+id.ToString()+"' ";
                using (SqlDataAdapter ad = new SqlDataAdapter(query, con))
                {
                    DataSet ds1 = new DataSet();
                    ad.Fill(ds1, "Table_SubTech");
                    listBox1.DataSource = ds1.Tables[0];
                    listBox1.DisplayMember = "SubTech";
                    //comboBox2.ValueMember = "SubTech";
                   
                }
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            //e.Effect = DragDropEffects.Copy;
           
            //ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.listBox1()");
            //if (sender.Name == myItems(0).ListView.Name)
            //    return;
            //if (e.Data.GetDataPresent("System.Windows.Forms.ListViewItem()"))
            //{
            //    e.Effect = DragDropEffects.Move;
            //}
            //else
            //{
            //    e.Effect = DragDropEffects.None;
            //}


        }

        private void listBox1_DragDrop(object sender, DragEventArgs e)
        {
            //string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            //int i;
            //for (i = 0; i < s.Length; i++)
            //    listBox1.Items.Add(s[i]);

            //ListViewItem myItem = default(ListViewItem);
            //ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");
            //foreach (ListViewItem I in myItems)
            //{
            //    myItem = new ListViewItem();
            //    myItem.Text = I.Text;
            //    myItem.ImageIndex = I.ImageIndex;
            //    if (sender.finditemwithtext(I.Text) == null)
            //    {
            //        sender.items.@add(myItem);
            //    }
            //}
            //if (sender.Name == myItems(0).ListView.Name)
            //    return;
            //if (object.ReferenceEquals(sender, listBox1))
            //{
            //    listBox1.Items.Remove(listBox1.SelectedItems.Item(0));
            //}
            //else
            //{
            //    listBox1.Items.Remove(listBox1.SelectedItems.Item(0));
            //}


        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listBox1_MouseDown(object sender, MouseEventArgs e)
        {
            //int IndexofItem = listBox1.IndexFromPoint(e.X, e.Y);
            //if (IndexofItem >= 0 && IndexofItem < listBox1.Items.Count)
            //{
            //    listBox1.DoDragDrop(listBox1.Items[IndexofItem], DragDropEffects.Copy);
            //}
        }

        private void listBox2_DragDrop(object sender, DragEventArgs e)
        {
            //if (e.Data.GetDataPresent(DataFormats.StringFormat))
            //{
            //    if (indexOfItemUnderMouseToDrop >= 0 && indexOfItemUnderMouseToDrop < listBox2.Items.Count)
            //    {
            //        listBox2.Items.Insert(indexOfItemUnderMouseToDrop, e.Data.GetData(DataFormats.Text));
            //    }
            //    else
            //    {
            //        // add the selected string to bottom of list
            //        listBox2.Items.Add(e.Data.GetData(DataFormats.Text));
            //    }


            //}
            //ListViewItem myItem = default(ListViewItem);
            //ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");
            //foreach (ListViewItem I in myItems)
            //{
            //    myItem = new ListViewItem();
            //    myItem.Text = I.Text;
            //    myItem.ImageIndex = I.ImageIndex;
            //    if (sender.finditemwithtext(I.Text) == null)
            //    {
            //        sender.items.@add(myItem);
            //    }
            //}
            //if (sender.Name == myItems(0).ListView.Name)
            //    return;
            //if (object.ReferenceEquals(sender, listBox1))
            //{
            //    listBox2.Items.Remove(listBox2.SelectedItems.Item(0));
            //}
            //else
            //{
            //    listBox1.Items.Remove(listBox1.SelectedItems.Item(0));
            //}

        }

        private void listBox2_DragEnter(object sender, DragEventArgs e)
        {
            //if (e.Data.GetDataPresent(DataFormats.StringFormat) && (e.AllowedEffect == DragDropEffects.Copy))
            //    e.Effect = DragDropEffects.Copy;
            //else
            //    e.Effect = DragDropEffects.Move;
            //ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");
            //if (sender.Name == myItems(0).ListView.Name)
            //    return;
            //if (e.Data.GetDataPresent("System.Windows.Forms.ListViewItem()"))
            //{
            //    e.Effect = DragDropEffects.Move;
            //}
            //else
            //{
            //    e.Effect = DragDropEffects.None;
            //}

        }

        private void listBox2_DragOver(object sender, DragEventArgs e)
        {
            //indexOfItemUnderMouseToDrop =
            //    listBox2.IndexFromPoint(listBox2.PointToClient(new Point(e.X, e.Y)));

            //if (indexOfItemUnderMouseToDrop != ListBox.NoMatches)
            //{
            //    // if the computed index is not within listBox2, then put it at the end (bottom)
            //    label1.Text = "\'" + e.Data.GetData(DataFormats.Text) + "\'" + " will be placed  before item #" + (indexOfItemUnderMouseToDrop + 1) +
            //                     "\n which is " + listBox2.SelectedItem;
            //    // pass the location back to use in the dragDrop event method.
            //    listBox2.SelectedIndex = indexOfItemUnderMouseToDrop;

            //}
            //else
            //{
            //    // prompt the user where the drop will occur
            //    label1.Text = "\'" + e.Data.GetData(DataFormats.Text) + "\'" + " will be added to the bottom of the listBox.";
            //    // save the intended drop location as an index number into the listBox2 Item collection.
            //    listBox2.SelectedIndex = indexOfItemUnderMouseToDrop;
            //}

            //// if  the MouseDown event set the DragDrop operation to be a move event
            //// immediately delete the item.  This has the desirable effect of
            //// deleting any duplicate strings that might have been moved into
            //// listBox2
            //if (e.Effect == DragDropEffects.Move)  // When moving an item within listBox2
            //    listBox2.Items.Remove((string)e.Data.GetData(DataFormats.Text));

            //// fill the informational listBox3
            ////eventTime = DateTime.Now;
            //GiveInfoAboutDragDropEvent(eventTime, "listBox2_DragOver", sender, e);
        }

        private void listView1_DragDrop(object sender, DragEventArgs e)
        {
            ListViewItem myItem = default(ListViewItem);
            ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");
            foreach (ListViewItem I in myItems)
            {
                myItem = new ListViewItem();
                myItem.Text = I.Text;
                myItem.ImageIndex = I.ImageIndex;
                if (sender.finditemwithtext(I.Text) == null)
                {
                    sender.items.@add(myItem);
                }
            }
            if (sender.Name == myItems(0).ListView.Name)
                return;
            if (object.ReferenceEquals(sender, ListView1))
            {
                ListView2.Items.Remove(ListView2.SelectedItems.Item(0));
            }
            else
            {
                ListView1.Items.Remove(ListView1.SelectedItems.Item(0));
            }

        }

        private void listView2_DragDrop(object sender, DragEventArgs e)
        {
            ListViewItem myItem = default(ListViewItem);
            ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");
            foreach (ListViewItem I in myItems)
            {
                myItem = new ListViewItem();
                myItem.Text = I.Text;
                myItem.ImageIndex = I.ImageIndex;
                if (sender.finditemwithtext(I.Text) == null)
                {
                    sender.items.@add(myItem);
                }
            }
            if (sender.Name == myItems(0).ListView.Name)
                return;
            if (object.ReferenceEquals(sender, ListView1))
            {
                ListView2.Items.Remove(ListView2.SelectedItems.Item(0));
            }
            else
            {
                ListView1.Items.Remove(ListView1.SelectedItems.Item(0));
            }

        }

        private void listView1_DragEnter(object sender, DragEventArgs e)
        {
            ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");
            if (sender.Name == myItems(0).ListView.Name)
                return;
            if (e.Data.GetDataPresent("System.Windows.Forms.ListViewItem()"))
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }

        }

        private void listView2_DragEnter(object sender, DragEventArgs e)
        {
            ListViewItem[] myItems = e.Data.GetData("System.Windows.Forms.ListViewItem()");
            if (sender.Name == myItems(0).ListView.Name)
                return;
            if (e.Data.GetDataPresent("System.Windows.Forms.ListViewItem()"))
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }

        }

       
    }
}

error.JPG
error.JPG
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 14

Expert Comment

by:systan
ID: 33454185
The code show's, drag and drop of listbox1 to listbox2 to listbox1, vice versa in c#.net code.
I'll fix up your full code after you have done this new code to test.
//Put this code in your DragDrop Events in Listbox1 and Listbox2

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

		{

                ListBox lb = sender as ListBox;

                if (lb.SelectedItem == e.Data.GetData(DataFormats.Text)) return;

                lb.Items.Add(e.Data.GetData(DataFormats.Text));

		}





//Put this code in your DragEnter Events in Listbox1 and Listbox2

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

		{

            e.Effect = DragDropEffects.Copy;

        }







//Put this code in your MouseDown Events in Listbox1 OR/AND Listbox2

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

        {

            ListBox lb = sender as ListBox;

            lb.DoDragDrop(lb.SelectedItem, DragDropEffects.Copy);

        }

Open in new window

0
 

Author Comment

by:ANINDYA
ID: 33454456
Expert Systan
I have used your code and used a new winform also ..
But no item is copied in the listbox2.
please see the code whether I am using porperly or not.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NonrectangularForm
{
    public partial class FormTextListBoxDragDrop : Form
    {
        public FormTextListBoxDragDrop()
        {
            InitializeComponent();
        }

        private void FormTextListBoxDragDrop_Load(object sender, EventArgs e)
        {

        }

        private void listBox1_DragDrop(object sender, DragEventArgs e)
        {
            ListBox lb = sender as ListBox;
            if (lb.SelectedItem == e.Data.GetData(DataFormats.Text)) return;
            lb.Items.Add(e.Data.GetData(DataFormats.Text));

        }

        private void listBox2_DragDrop(object sender, DragEventArgs e)
        {
            ListBox lb = sender as ListBox;
            if (lb.SelectedItem == e.Data.GetData(DataFormats.Text)) return;
            lb.Items.Add(e.Data.GetData(DataFormats.Text));

        }

        private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;

        }

        private void listBox2_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;

        }

        private void listBox1_MouseDown(object sender, MouseEventArgs e)
        {
            ListBox lb = sender as ListBox;
            lb.DoDragDrop(lb.SelectedItem, DragDropEffects.Copy);

        }

        private void listBox2_MouseDown(object sender, MouseEventArgs e)
        {
            ListBox lb = sender as ListBox;
            lb.DoDragDrop(lb.SelectedItem, DragDropEffects.Copy);

        }
    }
}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;



namespace NonrectangularForm

{

    public partial class FormTextListBoxDragDrop : Form

    {

        public FormTextListBoxDragDrop()

        {

            InitializeComponent();

        }



        private void FormTextListBoxDragDrop_Load(object sender, EventArgs e)

        {



        }



        private void listBox1_DragDrop(object sender, DragEventArgs e)

        {

            ListBox lb = sender as ListBox;

            if (lb.SelectedItem == e.Data.GetData(DataFormats.Text)) return;

            lb.Items.Add(e.Data.GetData(DataFormats.Text));



        }



        private void listBox2_DragDrop(object sender, DragEventArgs e)

        {

            ListBox lb = sender as ListBox;

            if (lb.SelectedItem == e.Data.GetData(DataFormats.Text)) return;

            lb.Items.Add(e.Data.GetData(DataFormats.Text));



        }



        private void listBox1_DragEnter(object sender, DragEventArgs e)

        {

            e.Effect = DragDropEffects.Copy;



        }



        private void listBox2_DragEnter(object sender, DragEventArgs e)

        {

            e.Effect = DragDropEffects.Copy;



        }



        private void listBox1_MouseDown(object sender, MouseEventArgs e)

        {

            ListBox lb = sender as ListBox;

            lb.DoDragDrop(lb.SelectedItem, DragDropEffects.Copy);



        }



        private void listBox2_MouseDown(object sender, MouseEventArgs e)

        {

            ListBox lb = sender as ListBox;

            lb.DoDragDrop(lb.SelectedItem, DragDropEffects.Copy);



        }

    }

}

Open in new window

error.JPG
0
 

Author Comment

by:ANINDYA
ID: 33454509
Expert Systan
I will not be able to reply your suggestion now as I am from India and here it is 7.30 PM and my office is closing .
Tomorrow at 9.30 AM I will again come and then I will be able to reply to  your suggestions.
Sorry for that .
Please do not think I am not responding to your suggestions for the time being .
Good night.
Thanking you
Anindya
0
 
LVL 14

Accepted Solution

by:
systan earned 500 total points
ID: 33456228
I guess you did not put on the property events,
You should add this, if you did not put any of them
        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.AllowDrop = true;
            listBox2.AllowDrop = true;
        }

Be sure also to put the events on listbox_dragenter, listbox_dragdrop, listbox_mousedown
0
 
LVL 14

Expert Comment

by:systan
ID: 33459937
select events on listbox_dragenter, listbox_dragdrop, listbox_mousedown
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;



namespace NonrectangularForm

{

    public partial class FormTextListBoxDragDrop : Form

    {

        public FormTextListBoxDragDrop()

        {

            InitializeComponent();

        }



        private void FormTextListBoxDragDrop_Load(object sender, EventArgs e)

        {



        }



        private void listBox1_DragDrop(object sender, DragEventArgs e)

        {

            ListBox lb = sender as ListBox;

            if (lb.SelectedItem == e.Data.GetData(DataFormats.Text)) return;

            lb.Items.Add(e.Data.GetData(DataFormats.Text));



        }



        private void listBox_DragDrop(object sender, DragEventArgs e)

        {

            ListBox lb = sender as ListBox;

            if (lb.SelectedItem == e.Data.GetData(DataFormats.Text)) return;

            lb.Items.Add(e.Data.GetData(DataFormats.Text));



        }



        private void listBox_DragEnter(object sender, DragEventArgs e)

        {

            e.Effect = DragDropEffects.Copy;



        }



        private void listBox_MouseDown(object sender, MouseEventArgs e)

        {

            ListBox lb = sender as ListBox;

            lb.DoDragDrop(lb.SelectedItem, DragDropEffects.Copy);



        }



        

    }

}

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 33460765
This is my last comment, and I've made a listbox to listbox control for you to close this question if possible.

Listbox1 copies items to Listbox2
Listbox1 can't copy items if Item's already exist in Listbox2
Listbox1 drop's item to Listbox2 if Listbox2 item's doesn't exist.
Listbox2 item's can be removed by dragging the item's out from Listbox2 box.
Listbox2 item's can be interchanged if item's dragged outside and return to Listbox2.

Here's the link;
http://www.experts-exchange.com/blogs/systan/B_2924-Add-Items-to-Listbox-from-another-Listbox.html
0
 

Author Comment

by:ANINDYA
ID: 33460866
Expert Systan
I am too happy to see the code you provided to me.
Yes you are correct that I had not put those instructions in the load events.
Thanking you for the responses you provided to me.

Expert Systan I have a request to you that is few days ago I put two questions on EE and then although many experts have replied but I am not getting the correct desired output .

Expert Systan if you can do a bit of devour to me then please put a glance upon those questions .
I am providing you the URLs of those questions and if you have a bit of free time please glance upon them.

Thanking for finding time for me.
Thanks for replying  .
Take regards ,
Anindya Chatterjee
Bangalore
India
0
 

Author Closing Comment

by:ANINDYA
ID: 33460876
Expert Systan
Thanks for the reply .
Hoping you will render me some more helps in future.
Actually I am a fresher so I do have a lot of queries and doubts .
I will be grateful  if you provide me the same in future.
Thanking you ,
Take my regards,
Anindya Chatterjee
Bangalore
India
0
 

Author Comment

by:ANINDYA
ID: 33460937
0
 
LVL 14

Expert Comment

by:systan
ID: 33461275
Thank you;
I'll responce now;

Have you look at this link ??????????????      
The link shows a complete listbox to/from listbox controls

Here's the link;
http://www.experts-exchange.com/blogs/systan/B_2924-Add-Items-to-Listbox-from-another-Listbox.html


And Yes, I'LL try to comment once more in your given links.
0
 
LVL 14

Expert Comment

by:systan
ID: 33471019
You've never visited that link I gave you, the link has a perfect solution for your problem.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hangfire / asp.net sample 3 30
.Net application crashing 6 21
Make a border less form movable 2 14
bulid json format 3 21
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

747 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

18 Experts available now in Live!

Get 1:1 Help Now