From b0272c6014fac8d44a266cc3ef016bc6f36d2745 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Feb 2012 18:54:02 +0000 Subject: [PATCH] Return an invalid item from wxDataViewCtrl::GetItemByRow() for invalid rows. This function is called in many places in the code with possibly invalid (i.e. out of range) row, so handle it gracefully inside it in virtual list control case. This is consistent with the behaviour in non-virtual case and with that of GetRowByItem(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70717 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/dataview.h | 2 ++ src/generic/datavgen.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index c2cf345a4c..89b0461623 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -199,6 +199,8 @@ public: protected: virtual void EnsureVisible( int row, int column ); + // Notice that row here may be invalid (i.e. >= GetRowCount()), this is not + // an error and this function simply returns an invalid item in this case. virtual wxDataViewItem GetItemByRow( unsigned int row ) const; virtual int GetRowByItem( const wxDataViewItem & item ) const; diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 21c53c66da..716d4b9bf9 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -2970,15 +2970,20 @@ wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row) co wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const { + wxDataViewItem item; if (IsVirtualList()) { - return wxDataViewItem( wxUIntToPtr(row+1) ); + if ( row < GetRowCount() ) + item = wxDataViewItem(wxUIntToPtr(row+1)); } else { wxDataViewTreeNode *node = GetTreeNodeByRow(row); - return node ? node->GetItem() : wxDataViewItem(); + if ( node ) + item = node->GetItem(); } + + return item; } bool