Drag and Drop in a ListBox control

  • Thread starter Thread starter CoolWriter
  • Start date Start date
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.
 
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];
}
 
Back
Top