定义多个Listbox,可以实现相互拖动,如listbox1,listbox2,设置如下allowdrop=true和
this.listBox2.DragDrop += new System.Windows.Forms.DragEventHandler(this.ListBox1_DragDrop);
this.listBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ListBox1_MouseDown);
this.listBox2.DragOver += new System.Windows.Forms.DragEventHandler(this.ListBox1_DragOver);
private
void
moveUpListBox(ListBox ListBox1)
//
向上移动
... {
//by 闫磊 Email:Landgis@126.com,yanleigis@21cn.com 2007.10.11
//若不是第一行则上移
if (ListBox1.SelectedIndex > 0)
...{
int index = ListBox1.SelectedIndex;
string temp = ListBox1.Items[index - 1].ToString();
ListBox1.Items[index - 1] = ListBox1.SelectedItem.ToString(); ;
ListBox1.Items[index] = temp;
ListBox1.SelectedIndex = index - 1;
}
}
private void moveDownListBox(ListBox ListBox1) /**/ /**/
... {
//by 闫磊 Email:Landgis@126.com,yanleigis@21cn.com 2007.10.11
//若不是第一行则上移
if (ListBox1.SelectedIndex > 0)
...{
int index = ListBox1.SelectedIndex;
string temp = ListBox1.Items[index - 1].ToString();
ListBox1.Items[index - 1] = ListBox1.SelectedItem.ToString(); ;
ListBox1.Items[index] = temp;
ListBox1.SelectedIndex = index - 1;
}
}
private void moveDownListBox(ListBox ListBox1) /**/ /**/