I tried what you posted, and it seems to me that it only checks if a certain item exists in the listBox. Maybe I described my question wrong Lets say I have 6 items in my listBox :
687,
365,
489,
687,
634,
687
What I need to do is check the listBox to see if there are duplicate items. In this case, the duplicate item is 687. Do you understand what I am saying.
ListBox
Talbengal
I tried what you posted, and it seems to me that it only checks if a certain item exists in the listBox. Maybe I described my question wrong Lets say I have 6 items in my listBox :
687,
365,
489,
687,
634,
687
What I need to do is check the listBox to see if there are duplicate items. In this case, the duplicate item is 687. Do you understand what I am saying.
rgdonato
Ahh you are checking to see if the listbox already contains duplicates... you can do something along the lines of this:
bool found = false;
for ( int i = 0; i < listBox.Items.Count; i++ )
{
// Reset found
found = false;
for ( int j = 0; j < listBox.Items.Count; j++ )
if ( listBox.Items [ j ] == listBox.Items [ j ] )
found = true; // Do whatever you want to do with your duplicates here
}
Xavier Divini
int index = listbox.Items.IndexOf ( itemToCheckFor )
if ( -1 == index )
Item does not exist