From ff3b3269dd55fb9ae25e719ce620d703da28f53e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 17 Jan 2018 10:10:38 +0100 Subject: [PATCH] Fix adding items to wxDataViewCtrl broken in the last commit SetHasChildren(true) must be called before checking GetChildNodes() if the parent hadn't had any items in the initial model. Also remove the assert checking that the node is open in BuildTreeHelper() as we may need to build even a closed tree branch. --- src/generic/datavgen.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index e361ef6606..dfc7c2c489 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -2739,6 +2739,8 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData if ( !parentNode ) return false; + parentNode->SetHasChildren(true); + // If the parent node isn't and hadn't been opened yet, we don't have // anything to do here, all the items will be added to it when it's // opened for the first time. @@ -2749,7 +2751,6 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData wxDataViewTreeNode *itemNode = new wxDataViewTreeNode(parentNode, item); itemNode->SetHasChildren(GetModel()->IsContainer(item)); - parentNode->SetHasChildren(true); if ( GetSortOrder().IsNone() ) { @@ -3963,8 +3964,8 @@ static void BuildTreeHelper( wxDataViewMainWindow *window, const wxDataViewModel node->InsertChild(window, n, index); } - wxASSERT( node->IsOpen() ); - node->ChangeSubTreeCount(+num); + if ( node->IsOpen() ) + node->ChangeSubTreeCount(+num); } void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)