Drag and Drop in a ListBox control

C

CoolWriter

Hi,

How can I drag and drop the items of a ListBox?

For example, how can I drag the first item to the third items position
in a ListBox?

Thanks.
 
M

Marie

Hi,

How can I drag and drop the items of a ListBox?

For example, how can I drag the first item to the third items position
in a ListBox?

Thanks.



----------------------------------------------------------

----------------------------------------------------------
color]


Add these two events to your listbox and declare object thing as a
public variable


public void listBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
int temp;
temp = listBox1.SelectedIndex;
listBox1.Items.Remove(thing);
listBox1.Items.Insert(temp, thing);
}

public void listBox1_MouseDown(object
sender,System.Windows.Forms.MouseEventArgs e )
{
int temp;
temp = listBox1.SelectedIndex;
thing = listBox1.Items[temp];
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top