+ m_listCtrl->InsertColumn(0, _T("First Column"));
+ m_listCtrl->InsertColumn(1, _T("Second Column"));
+ m_listCtrl->SetColumnWidth(0, 150);
+ m_listCtrl->SetColumnWidth(1, 150);
+
+ m_listCtrl->SetItemCount(1000000);
+}
+
+void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
+{
+ wxStopWatch sw;
+
+ m_listCtrl->SortItems(MyCompareFunction, 0);
+
+ m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
+ m_listCtrl->GetItemCount(),
+ sw.Time()));
+}
+
+void MyFrame::OnShowSelInfo(wxCommandEvent& event)
+{
+ int selCount = m_listCtrl->GetSelectedItemCount();
+ wxLogMessage(_T("%d items selected:"), selCount);
+
+ // don't show too many items
+ size_t shownCount = 0;
+
+ long item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+ while ( item != -1 )
+ {
+ wxLogMessage(_T("\t%ld (%s)"),
+ item, m_listCtrl->GetItemText(item).c_str());
+
+ if ( ++shownCount > 10 )
+ {
+ wxLogMessage(_T("\t... more selected items snipped..."));
+ break;
+ }
+
+ item = m_listCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+ }
+}
+
+void MyFrame::OnShowColInfo(wxCommandEvent& event)
+{
+ int count = m_listCtrl->GetColumnCount();
+ wxLogMessage(wxT("%d columns:"), count);
+ for ( int c = 0; c < count; c++ )
+ {
+ wxLogMessage(wxT("\tcolumn %d has width %d"), c,
+ m_listCtrl->GetColumnWidth(c));
+ }
+}
+
+void MyFrame::OnUpdateShowColInfo(wxUpdateUIEvent& event)
+{
+ event.Enable( (m_listCtrl->GetWindowStyleFlag() & wxLC_REPORT) != 0 );
+}
+
+void MyFrame::OnToggleMultiSel(wxCommandEvent& WXUNUSED(event))
+{
+ long flags = m_listCtrl->GetWindowStyleFlag();
+ if ( flags & wxLC_SINGLE_SEL )
+ flags &= ~wxLC_SINGLE_SEL;
+ else
+ flags |= wxLC_SINGLE_SEL;
+
+ m_logWindow->WriteText(wxString::Format(wxT("Current selection mode: %sle\n"),
+ (flags & wxLC_SINGLE_SEL) ? _T("sing") : _T("multip")));
+
+ RecreateList(flags);
+}
+
+void MyFrame::OnSetFgColour(wxCommandEvent& WXUNUSED(event))
+{
+ m_listCtrl->SetForegroundColour(wxGetColourFromUser(this));
+ m_listCtrl->Refresh();
+}
+
+void MyFrame::OnSetBgColour(wxCommandEvent& WXUNUSED(event))
+{
+ m_listCtrl->SetBackgroundColour(wxGetColourFromUser(this));
+ m_listCtrl->Refresh();
+}
+
+void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event))
+{
+ m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), _T("Appended item"));
+}
+
+void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event))
+{
+ long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
+ wxLIST_STATE_FOCUSED);
+
+ if ( itemCur != -1 )
+ {
+ m_listCtrl->EditLabel(itemCur);
+ }
+ else
+ {
+ m_logWindow->WriteText(_T("No item to edit"));
+ }
+}
+
+void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
+{
+ if ( m_listCtrl->GetItemCount() )
+ {
+ m_listCtrl->DeleteItem(0);
+ }
+ else
+ {
+ m_logWindow->WriteText(_T("Nothing to delete"));
+ }
+}
+
+void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
+{
+ wxStopWatch sw;
+
+ m_listCtrl->DeleteAllItems();
+
+ m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
+ m_listCtrl->GetItemCount(),
+ sw.Time()));