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
This commit is contained in:
Vadim Zeitlin 2012-02-27 18:54:02 +00:00
parent f2bf2d71c1
commit b0272c6014
2 changed files with 9 additions and 2 deletions

View File

@ -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;

View File

@ -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