private void button1_Click(object sender, EventArgs e)
{
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (lbxLength > iselect && iselect > 0)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect - 1, oTempItem);
this.listBox1.SelectedIndex = iselect - 1;
}
}
private void button2_Click(object sender, EventArgs e)
{
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (iselect <lbxLength-1)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect + 1, oTempItem);
this.listBox1.SelectedIndex = iselect + 1;
}
}
{
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (lbxLength > iselect && iselect > 0)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect - 1, oTempItem);
this.listBox1.SelectedIndex = iselect - 1;
}
}
private void button2_Click(object sender, EventArgs e)
{
int lbxLength = this.listBox1.Items.Count;//listbox的长度
int iselect = this.listBox1.SelectedIndex;//listbox选择的索引
if (iselect <lbxLength-1)
{
object oTempItem = this.listBox1.SelectedItem;
this.listBox1.Items.RemoveAt(iselect);
this.listBox1.Items.Insert(iselect + 1, oTempItem);
this.listBox1.SelectedIndex = iselect + 1;
}
}