From 685f9ff57d87fdfdb3b9d84ed63f1ee37ad39d04 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 4 Nov 2018 17:03:16 +0100 Subject: [PATCH] Fix bug in GetRowByItem() in generic wxDataViewCtrl If the item was not found at all, which can happen if all its parents are not expanded, this function still returned a valid but completely wrong row index. This affected many functions which could call it for the items which were not necessarily visible, i.e. all of them except for the event handlers as events can only affect the visible items, including but not limited to SetCurrentItem(), all the selection-related functions, all the expansion-related functions, EnsureVisible(), HitTest() and GetItemRect(). --- src/generic/datavgen.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index c83ce64821..42e55ebb2e 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3920,7 +3920,9 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) const // the parent chain was created by adding the deepest parent first. // so if we want to start at the root node, we have to iterate backwards through the vector ItemToRowJob job( item, parentChain.rbegin() ); - Walker( m_root, job ); + if ( !Walker( m_root, job ) ) + return -1; + return job.GetResult(); } }