请问,如何按button使得listBox的选定项上下移动
如何按button1,使得listBox的选定项上下移动
[解决办法]
- C# code
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--; } }
[解决办法]
删掉选中的,插到前面或后面
[解决办法]
判断边界,下移
- C# code
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;