void MyFrame::OnListBox(wxCommandEvent& event) { int index = event.GetSelection(); wxString item = m_listBox->GetString(index); // do something with the selected item }
void MyFrame::OnListColClick(wxListEvent& event) { int col = event.GetColumn(); bool ascending = true; if (col == m_sortCol) ascending = !m_sortAscending; m_sortCol = col; m_sortAscending = ascending; m_listCtrl->SortItems(&MyFrame::CompareItems, this); } int MyFrame::CompareItems(long item1, long item2, long sortData) { MyFrame* frame = (MyFrame*)sortData; wxString text1 = frame->m_listCtrl->GetItemText(item1, frame->m_sortCol); wxString text2 = frame->m_listCtrl->GetItemText(item2, frame->m_sortCol); int result = text1.Cmp(text2); if (!frame->m_sortAscending) result *= -1; return result; }This example shows how to handle the event generated when a user clicks on a column header in a list control. The code sorts the items in the list according to the column that the user clicks on. Both of these examples demonstrate how the wxListEvent class is used to handle events generated by listbox controls. The wxListEvent class is part of the wxWidgets library.