I've got a Method:
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
}
THIS DONT WORKS! :(
Fault: InvalidArgument=Value of '1' is not valid for 'index'.
Parameter name: index
And something like that:
if(listBox.Items.Contains("hello"))
{
DONT FILL
}
Dont works too :(
What can I do?
Try:
Do this:
You should try something along the lines of
if your project is ASP
you should do
if it's WPF, not sure which ListBox you're talking about. Obviously this isn't the most elegant solution, but I suppose it's appropriate if you're just starting to learn C#.
listBox.Items.Contains("hello")
should work fine.Try this
or simply try this
I solved the problem.. I just used myListBox.Items.Clear();