// initialize the controls contents
- for ( int i = 0; i < n; i++ )
- {
- Append(choices[i]);
- }
+ Append(n, choices);
// and now we may finally size the control properly (if needed)
SetInitialSize(size);
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();
}
void* wxChoice::DoGetItemClientData(unsigned int n) const
{
LPARAM rc = SendMessage(GetHwnd(), CB_GETITEMDATA, n, 0);
- if ( rc == CB_ERR )
+ if ( rc == CB_ERR && GetLastError() != ERROR_SUCCESS )
{
wxLogLastError(wxT("CB_GETITEMDATA"));
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);