日期:2014-05-18  浏览次数:20953 次

请问,如何按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;