代码如下:
//originListBox是源ListBox,表示要从中选择项添加到另一个ListBox
//aimListBox目标ListBox,表示被复制数据的ListBox
private void MoveListBoxItem(ListBox originListBox, ListBox aimListBox)
{
int index = 0;//listbox中被选中项的当前项的索引
//将源Listbox中的选中项添加到目标Listbox中
for (int i = 0; i < originListBox.SelectedIndices .Count ; i++)
{
index = originListBox.SelectedIndices[i];
aimListBox.Items.Add(originListBox.Items[index]);
}
//将源ListBox中的选中项逐个删除
//遍历源ListBox中的被选中的项,如果存在被选中的项,则删除被选中项中的第一个项
while (originListBox.SelectedIndices.Count !=0)
{
index = originListBox.SelectedIndices[0];
originListBox.Items.RemoveAt(index);
}
}
//originListBox是源ListBox,表示要从中选择项添加到另一个ListBox
//aimListBox目标ListBox,表示被复制数据的ListBox
private void MoveListBoxItem(ListBox originListBox, ListBox aimListBox)
{
int index = 0;//listbox中被选中项的当前项的索引
//将源Listbox中的选中项添加到目标Listbox中
for (int i = 0; i < originListBox.SelectedIndices .Count ; i++)
{
index = originListBox.SelectedIndices[i];
aimListBox.Items.Add(originListBox.Items[index]);
}
//将源ListBox中的选中项逐个删除
//遍历源ListBox中的被选中的项,如果存在被选中的项,则删除被选中项中的第一个项
while (originListBox.SelectedIndices.Count !=0)
{
index = originListBox.SelectedIndices[0];
originListBox.Items.RemoveAt(index);
}
}