如果ListBox包含,请不要添加 [英] if ListBox Contains, don't add
本文介绍了如果ListBox包含,请不要添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个方法:
FillListBox();
我从不同的地方调用此方法.但是有时它会被加载两次!
I call this method from different places.. But sometimes it happens, that things were loaded twice!
现在我正在尝试做类似的事情:
Now I'm trying to do something like:
if (listBox.Items[1].ToString() == "hello")
{
DO NOT FILL
}
else
{
FILL
}
这没用! :(
Fault: InvalidArgument=Value of '1' is not valid for 'index'.
Parameter name: index
类似的东西:
if(listBox.Items.Contains("hello"))
{
DONT FILL
}
也不起作用:(
我该怎么办?
推荐答案
我解决了这个问题..我只是使用myListBox.Items.Clear();
I solved the problem.. I just used myListBox.Items.Clear();
这篇关于如果ListBox包含,请不要添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文