From d49abaaec461b22815789f4017bf1db5b3cbcd32 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 15 Oct 2015 23:46:02 +0200 Subject: [PATCH] Refresh virtual wxListCtrl in wxMSW after deleting all its items In principle, calling DeleteAllItems() on a virtual list control doesn't make sense at all, but apparently people actually do it and it mostly works except that the controls scrollbars are not updated, so add a call to Refresh() to update them too, for consistency with DeleteItem() which similarly doesn't make sense for virtual controls but where we also explicitly support them for some reason. --- src/msw/listctrl.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 73b51d7f54..e38f336df9 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1415,7 +1415,18 @@ bool wxListCtrl::DeleteAllItems() { // Calling ListView_DeleteAllItems() will always generate an event but we // shouldn't do it if the control is empty - return !GetItemCount() || ListView_DeleteAllItems(GetHwnd()) != 0; + if ( !GetItemCount() ) + return true; + + if ( !ListView_DeleteAllItems(GetHwnd()) ) + return false; + + // Virtual controls don't refresh their scrollbar position automatically, + // do it for them when clearing them. + if ( IsVirtual() ) + Refresh(); + + return true; } // Deletes all items