void MyFrame::OnListSelected(wxListEvent& event) { int itemIndex = event.GetIndex(); wxString itemName = listCtrl->GetItemText(itemIndex); wxString msg = wxString::Format("Selected item: %s", itemName); wxMessageBox(msg); }
void MyFrame::OnListRightClick(wxListEvent& event) { int itemIndex = event.GetIndex(); wxListItem item; item.SetId(listCtrl->GetId()); item.SetColumn(0); item.SetMask(wxLIST_MASK_TEXT); listCtrl->GetItem(item); wxString itemName = item.GetText(); wxString msg = wxString::Format("Right-clicked item: %s", itemName); wxMessageBox(msg); }In this example, we define an event handler for when a user right-clicks on an item in a list control. We use the GetIndex function to retrieve the index of the right-clicked item, and then use the GetItem function of the list control to retrieve the text of the item. We then display a message box with the name of the right-clicked item. Both examples use the wxWidgets library.