From 4dc78a33e0158e92fdc45c20896a0feed8704ab8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 17 Jan 2018 00:12:52 +0100 Subject: [PATCH] Fix adding items to a never opened branch of generic wxDataViewCtrl Calling ItemAdded() on a parent item that had never been opened yet "lost" all its children that initially existed in the model, as the corresponding subtree wasn't built any more in Expand() when this item was finally opened because the list of item children wasn't empty any more after ItemAdded() added the new child to it. Fix this by simply not doing anything in ItemAdded() in this situation, there is no need to update a closed tree branch immediately anyhow. --- src/generic/datavgen.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 8a584ce69a..e361ef6606 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -2739,6 +2739,14 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData if ( !parentNode ) return false; + // 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. + if ( !parentNode->IsOpen() && parentNode->GetChildNodes().empty() ) + { + return true; + } + wxDataViewTreeNode *itemNode = new wxDataViewTreeNode(parentNode, item); itemNode->SetHasChildren(GetModel()->IsContainer(item)); parentNode->SetHasChildren(true);