diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index f8d45031a2..adb528f533 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -1110,6 +1110,11 @@ public: This method does not take ownership of the image list, you have to delete it yourself. + Note that, unlike for most of the other methods of this class, it is + possible to call this function before the corresponding window is + created, i.e. do it in a constructor of a class derived from wxListCtrl + before calling Create(). + @see AssignImageList() */ void SetImageList(wxImageList* imageList, int which); diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 6b4be8208b..922a9809d8 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -320,6 +320,15 @@ bool wxListCtrl::Create(wxWindow *parent, if ( HasFlag(wxLC_LIST) ) m_colCount = 1; + // If SetImageList() had been called before the control was created, take + // it into account now. + if ( m_imageListNormal ) + ListView_SetImageList(GetHwnd(), GetHimagelistOf(m_imageListNormal), LVSIL_NORMAL); + if ( m_imageListSmall ) + ListView_SetImageList(GetHwnd(), GetHimagelistOf(m_imageListSmall), LVSIL_SMALL); + if ( m_imageListState ) + ListView_SetImageList(GetHwnd(), GetHimagelistOf(m_imageListState), LVSIL_STATE); + return true; } @@ -1551,6 +1560,13 @@ void wxListCtrl::SetImageList(wxImageList *imageList, int which) m_imageListState = imageList; m_ownsImageListState = false; } + + // It's possible that this function is called before the control is + // created, don't do anything else in this case -- the image list will be + // really set after creating it. + if ( !GetHwnd() ) + return; + (void) ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags); // For ComCtl32 prior 6.0 we need to re-assign all existing