Please refer to wxTextEntry documentation for the description of methods
operating with the text entry part of the combobox and to wxItemContainer
- for the methods operating with the list of strings.
+ for the methods operating with the list of strings. Notice that at least
+ under MSW wxComboBox doesn't behave correctly if it contains strings
+ differing in case only so portable programs should avoid adding such
+ strings to this control.
@beginStyleTable
@style{wxCB_SIMPLE}
virtual int GetSelection() const = 0;
/**
- Selects the item with the specified string in the control. This doesn't
- cause any command events to be emitted.
+ Selects the item with the specified string in the control.
+
+ This method doesn't cause any command events to be emitted.
+
+ Notice that this method is case-insensitive, i.e. the string is
+ compared with all the elements of the control case-insensitively and
+ the first matching entry is selected, even if it doesn't have exactly
+ the same case as this string and there is an exact match afterwards.
@param string
The string to select.
-
@return @true if the specified string has been selected, @false if it
wasn't found in the control.
*/
testitems.Add("item 0");
testitems.Add("item 1");
testitems.Add("item 2");
- testitems.Add("item 3");
+ testitems.Add("ITEM 2"); // The same as the last one except for case.
container->Append(testitems);
container->SetSelection(wxNOT_FOUND);
-
CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, container->GetSelection());
CPPUNIT_ASSERT_EQUAL("", container->GetStringSelection());
container->SetSelection(1);
-
CPPUNIT_ASSERT_EQUAL(1, container->GetSelection());
CPPUNIT_ASSERT_EQUAL("item 1", container->GetStringSelection());
- container->SetStringSelection("item 2");
+ CPPUNIT_ASSERT( container->SetStringSelection("item 2") );
+ CPPUNIT_ASSERT_EQUAL(2, container->GetSelection());
+ CPPUNIT_ASSERT_EQUAL("item 2", container->GetStringSelection());
+
+ // Check that selecting a non-existent item fails.
+ CPPUNIT_ASSERT( !container->SetStringSelection("bloordyblop") );
+ // Check that SetStringSelection() is case-insensitive.
+ CPPUNIT_ASSERT( container->SetStringSelection("ITEM 2") );
CPPUNIT_ASSERT_EQUAL(2, container->GetSelection());
CPPUNIT_ASSERT_EQUAL("item 2", container->GetStringSelection());
}