读书人

请教怎么按button使得listBox的选定

发布时间: 2012-06-04 14:48:03 作者: rapoo

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

读书人网 >C#

热点推荐