如何在两个ListBox
es之间进行匹配并将其从第二个ListBox
中删除?如何删除已存在于其他ListBox项目中的一个ListBox中的项目
例如,我有foo
在listbox1
,如果它也是listbox2
然后从listbox1
除去FOO。
如何在两个ListBox
es之间进行匹配并将其从第二个ListBox
中删除?如何删除已存在于其他ListBox项目中的一个ListBox中的项目
例如,我有foo
在listbox1
,如果它也是listbox2
然后从listbox1
除去FOO。
很简单:
foreach (var item in listBox1.Items)
listBox2.Items.Remove(item);
希望对大家有所帮助:)
根据问题,您已将列表框向后移动。 – itsme86
这应做到:
foreach(var item in listBox1.Items)
{
// check if listbox2 contains the current item in the foreach loop.
// don't forget to use: using System.Linq;
bool hasItem = listBox2.Items.Contains(item);
// if it has it than remove it
if(hasItem)
listBox2.Items.Remove(item);
}
你尝试过这么远吗? – Sach
看起来很直截了当。循环播放listbox2中的项目,并将它们从listbox1中删除。你究竟在干什么? – itsme86