I have a checkedListBox1 wich consist of a many lines with text.
What I am trying to do is to search trough this checkedListBox1 to see
if "Hello" could be found in this box and if it is found, this Item(Line) will
be selected.
I am not sure what could be wrong/missing with this code. ?

for( int i = 0; i < checkedListBox1->Text->Length; i++)
{
	
      if(checkedListBox1->Text->IndexOf(i).ToString() == "Hello")
     {
	checkedListBox1->Select();
     }

}

Maybe Lenght+1? What compiler system do you use?

> for( int i = 0; i < checkedListBox1->Text->Length; i++)
Edward doesn't understand how this is supposed to search the items. The Text property gives you the text of the currently selected item. Ed would expect something more like this:

for (int i = 0; i < checkedListBox1->Items->Count; ++i) {
  Object^ item = checkedListBox1->Items[i];

  if (checkedListBox1->GetItemText(item) == "Hello") {
    checkedListBox->SelectedIndex = i;

    // Found a match, so we're done
    break;
  }
}

Thank you. Yes it was ofcourse Items->Count;
This worked fine.

> for( int i = 0; i < checkedListBox1->Text->Length; i++)
Edward doesn't understand how this is supposed to search the items. The Text property gives you the text of the currently selected item. Ed would expect something more like this:

for (int i = 0; i < checkedListBox1->Items->Count; ++i) {
  Object^ item = checkedListBox1->Items[i];

  if (checkedListBox1->GetItemText(item) == "Hello") {
    checkedListBox->SelectedIndex = i;

    // Found a match, so we're done
    break;
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.