首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请教,怎么按button使得listBox的选定项上下移动

2012-06-04 
请问,如何按button使得listBox的选定项上下移动如何按button1,使得listBox的选定项上下移动[解决办法]C# c

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

热点排行