else if ( HasClientObjectData() )
oldObjData = GetClientObject(n);
+ // and also the selection if we're going to delete the item that was
+ // selected
+ const bool wasSelected = static_cast<int>(n) == GetSelection();
+
::SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
::SendMessage(GetHwnd(), CB_INSERTSTRING, n, (LPARAM)s.wx_str() );
else if ( oldObjData )
SetClientObject(n, oldObjData);
+ // and the selection
+ if ( wasSelected )
+ SetSelection(n);
+
+ // the width could have changed so the best size needs to be recomputed
InvalidateBestSize();
}
container->Append(testitems);
+ container->SetSelection(0);
container->SetString(0, "new item 0");
-#ifndef __WXOSX__
- container->SetString(2, "");
-#endif
-
CPPUNIT_ASSERT_EQUAL("new item 0", container->GetString(0));
+
+ // Modifying the item shouldn't deselect it.
+ CPPUNIT_ASSERT_EQUAL(0, container->GetSelection());
+
+ // wxOSX doesn't support having empty items in some containers.
#ifndef __WXOSX__
+ container->SetString(2, "");
CPPUNIT_ASSERT_EQUAL("", container->GetString(2));
#endif
}