]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/choice.cpp
fixes #13826
[wxWidgets.git] / src / msw / choice.cpp
index 03d3b3fb50fb1912af0de865e57f7abc7002850d..34dd9b817da0c8deb77c1d565a5dfb85bd532954 100644 (file)
@@ -358,6 +358,10 @@ void wxChoice::SetString(unsigned int n, const wxString& s)
     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() );
 
@@ -367,6 +371,11 @@ void wxChoice::SetString(unsigned int n, const wxString& s)
     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();
 }
 
@@ -544,7 +553,10 @@ void wxChoice::DoSetSize(int x, int y,
     const int hItem = SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0);
     int heightWithItems = 0;
     if (!HasFlag(wxCB_SIMPLE))
-        heightWithItems = height + hItem*nItems;
+        // The extra item (" + 1") is required to prevent a vertical
+        // scrollbar from appearing with comctl32.dll versions earlier
+        // than 6.0 (such as found in Win2k).
+        heightWithItems = height + hItem*(nItems + 1);
     else
         heightWithItems = SetHeightSimpleComboBox(nItems);