diff --git a/src/generic/treelist.cpp b/src/generic/treelist.cpp index 6c599100ae..3c6f26d955 100644 --- a/src/generic/treelist.cpp +++ b/src/generic/treelist.cpp @@ -572,12 +572,16 @@ void wxTreeListModel::DeleteItem(Node* item) void wxTreeListModel::DeleteAllItems() { + // Note that this must be called before actually deleting the items as + // clearing GTK+ wxDataViewCtrl results in SELECTION_CHANGED events being + // sent and these events contain pointers to the model items, so they must + // still be valid. + Cleared(); + while ( m_root->GetChild() ) { m_root->DeleteChild(); } - - Cleared(); } const wxString& wxTreeListModel::GetItemText(Node* item, unsigned col) const diff --git a/tests/controls/treelistctrltest.cpp b/tests/controls/treelistctrltest.cpp index d4a3ac96d6..02164ab3a1 100644 --- a/tests/controls/treelistctrltest.cpp +++ b/tests/controls/treelistctrltest.cpp @@ -39,6 +39,7 @@ private: CPPUNIT_TEST( Traversal ); CPPUNIT_TEST( ItemText ); CPPUNIT_TEST( ItemCheck ); + CPPUNIT_TEST( DeleteAll ); CPPUNIT_TEST_SUITE_END(); // Create the control with the given style. @@ -55,6 +56,7 @@ private: void Traversal(); void ItemText(); void ItemCheck(); + void DeleteAll(); // The control itself. @@ -231,4 +233,11 @@ void TreeListCtrlTestCase::ItemCheck() m_treelist->GetCheckedState(m_code) ); } +void TreeListCtrlTestCase::DeleteAll() +{ + m_treelist->DeleteAllItems(); + + CHECK( !m_treelist->GetFirstChild(m_treelist->GetRootItem()).IsOk() ); +} + #endif // wxUSE_TREELISTCTRL