diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 5cc6cf6dd4..1c4213098b 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -402,6 +402,12 @@ void MyFrame::OnToggleMacUseGeneric(wxCommandEvent& event) void MyFrame::OnGoTo(wxCommandEvent& WXUNUSED(event)) { + if ( m_listCtrl->IsEmpty() ) + { + wxLogMessage("Attempt go to item #3 when list is empty"); + return; + } + long index = 3; m_listCtrl->SetItemState(index, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); @@ -426,7 +432,14 @@ void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnToggleFirstSel(wxCommandEvent& WXUNUSED(event)) { - m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + if ( !m_listCtrl->IsEmpty() ) + { + m_listCtrl->SetItemState(0, (~m_listCtrl->GetItemState(0, wxLIST_STATE_SELECTED) ) & wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + } + else + { + wxLogMessage("Attempt toggle first item when list is empty"); + } } void MyFrame::OnDeselectAll(wxCommandEvent& WXUNUSED(event))