日期:2014-05-18 浏览次数:20953 次
private void button1_Click(object sender, EventArgs e) { if (this.listBox1.SelectedIndex < this.listBox1.Items.Count - 1) { this.listBox1.SelectedIndex++; } } private void button2_Click(object sender, EventArgs e) { if (this.listBox1.SelectedIndex > 0) { this.listBox1.SelectedIndex--; } }
------解决方案--------------------
删掉选中的,插到前面或后面
------解决方案--------------------
判断边界,下移
int nindex = this.listBox1.SelectedIndex + 1; var item = this.listBox1.SelectedItem; this.listBox1.Items.RemoveAt(this.listBox1.SelectedIndex); this.listBox1.Items.Insert(nindex, item); this.listBox1.SelectedIndex = nindex;