//--上移动作
//-------------------------------------------------------
private void Up()
{
if (ListBox1.SelectedIndex >0)
{
string t;
string s;
int index;
index=ListBox1.SelectedIndex;
t=ListBox1.SelectedItem.Text ;
s=ListBox1.SelectedItem.Value ;
ListBox1.SelectedItem.Text =ListBox1.Items[index-1].Text ;
ListBox1.SelectedItem.Value =ListBox1.Items[index-1].Value ;
ListBox1.Items[index-1].Text =t;
ListBox1.Items[index-1].Value =s;
ListBox1.SelectedIndex --;
}
}
//-------------------------------------------------------
//--下移动作
//-------------------------------------------------------
private void Down()
{
if (ListBox1.SelectedIndex <ListBox1.Items.Count-1 )
{
string t;
string s;
int index;
index=ListBox1.SelectedIndex;
t=ListBox1.SelectedItem.Text ;
s=ListBox1.SelectedItem.Value ;
ListBox1.SelectedItem.Text =ListBox1.Items[index+1].Text ;
ListBox1.SelectedItem.Value =ListBox1.Items[index+1].Value ;
ListBox1.Items[index+1].Text =t;
ListBox1.Items[index+1].Value =s;
ListBox1.SelectedIndex ++;
}
}
//-------------------------------------------------------
//--右移动作
//-------------------------------------------------------
private void MoveRight()
{
if (ListBox1.Items.Count>0 )
{
int i,index;
int count;
index=0;
count=ListBox1.Items.Count;
for (i=0;i<count;i++)
{
ListItem Item=ListBox1.Items[index];
if (ListBox1.Items[index].Selected ==true)
{
ListBox1.Items.Remove(Item);
ListBox2.Items.Add (Item);
index--;
}
index++;
}
}
}
本文介绍了一种在两个列表框之间移动元素的方法,并提供了向上移动、向下移动及向右侧移动元素的具体实现代码。通过这些操作可以有效地管理列表中的项,实现用户交互式的元素调整。
2216

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



