diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index f0179e06f5..d1d6e0e5fb 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -1315,7 +1315,7 @@ wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent, } // and try all the items (stop when we get to the one we started from) - while ( id != idParent && !GetItemText(id).Lower().StartsWith(prefix) ) + while ( id.IsOk() && (id != idParent) && !GetItemText(id).Lower().StartsWith(prefix) ) { id = GetNext(id); }