ListBox 中选中的项从一个移向另一个ListBox
/// <summary>
/// 移除ListBox中一个或多个选中项从lstFrom将选中的项移到lstTo
/// </summary>
/// <param name="lstFrom">选中的</param>
/// <param name="lstTo">添加的</param>
public static void RemoveMoreListBoxItem(ListBox lstFrom,ListBox lstTo)
{
if(lstFrom.SelectedItems!=null)
{
ListBox.SelectedObjectCollection obj=lstFrom.SelectedItems;
int n=obj.Count;
for(int i=0;i<n;i++)
{
lstTo.Items.Add(obj[i]);
}
if(lstFrom.SelectedItems.Count>0)
{
RemoveSelectedItems(lstFrom);//递归调用移除选中项
}
}
}
/// 移除ListBox中一个或多个选中项从lstFrom将选中的项移到lstTo
/// </summary>
/// <param name="lstFrom">选中的</param>
/// <param name="lstTo">添加的</param>
public static void RemoveMoreListBoxItem(ListBox lstFrom,ListBox lstTo)
{
if(lstFrom.SelectedItems!=null)
{
ListBox.SelectedObjectCollection obj=lstFrom.SelectedItems;
int n=obj.Count;
for(int i=0;i<n;i++)
{
lstTo.Items.Add(obj[i]);
}
if(lstFrom.SelectedItems.Count>0)
{
RemoveSelectedItems(lstFrom);//递归调用移除选中项
}
}
}
/// <summary>
/// 移除选中的项
/// </summary>
/// <param name="lstFrom">ListBox 要进行操作的ListBox</param>
public static void RemoveSelectedItems(ListBox lstFrom)
{
if(lstFrom.SelectedItems.Count>0)
{
lstFrom.Items.Remove(lstFrom.SelectedItems[0]);
RemoveSelectedItems(lstFrom);
}
}
/// 移除选中的项
/// </summary>
/// <param name="lstFrom">ListBox 要进行操作的ListBox</param>
public static void RemoveSelectedItems(ListBox lstFrom)
{
if(lstFrom.SelectedItems.Count>0)
{
lstFrom.Items.Remove(lstFrom.SelectedItems[0]);
RemoveSelectedItems(lstFrom);
}
}

浙公网安备 33010602011771号