向下
protected void Button2_Click(object sender, EventArgs e)
{
int i = this.ListBox1.SelectedIndex;
if ((i - 1) > -1 && i != -1)
{
ListItem li = this.ListBox1.SelectedItem;
this.ListBox1.Items.Remove(li);
this.ListBox1.Items.Insert(i - 1, li);
}
}
向上
protected void Button3_Click(object sender, EventArgs e)
{
int i = this.ListBox1.SelectedIndex;
if (i != this.ListBox1.Items.Count - 1)
{
ListItem li = this.ListBox1.SelectedItem;
this.ListBox1.Items.Remove(li);
this.ListBox1.Items.Insert(i + 1, li);
}
else { }
}
本文介绍了一个使用C#实现的功能,该功能允许用户通过按钮点击操作在ListBox中上下移动选定的列表项。具体实现了当用户点击“向下”按钮时,当前选中的列表项会向下移动一位;当点击“向上”按钮时,列表项则向上移动一位。
694

被折叠的 条评论
为什么被折叠?



