Search code examples
c++user-interfacewindows-7event-handlingwxwidgets

Can't catch EVT_LIST_BEGIN_LABEL_EDIT event when calling wxListCtrl::EditLabel (index)


I want to rename a selected list item in the wxListCtrl. I've been following example of the sample listctrl provided with wxwidgets, but it doesn't seem to work in my code.

The sample has this piece of code for calling changing the label of the item:

void MyFrame::OnEdit(wxCommandEvent& WXUNUSED(event))
{

// demonstrate cancelling editing: this currently is wxMSW-only
#ifdef __WXMSW__
if ( m_listCtrl->GetEditControl() )
{
    m_listCtrl->EndEditLabel(true);
}
else // start editing
#endif // __WXMSW__
{
    long itemCur = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL,
                                           wxLIST_STATE_FOCUSED);

    if ( itemCur != -1 )
    {
        m_listCtrl->EditLabel(itemCur);
    }
    else
    {
        m_logWindow->WriteText(wxT("No item to edit"));
    }
}

}

while mine looks like this:

void GUI::OnRename (wxCommandEvent &WXUNUSED (event))
{

  wxListCtrl *list ((wxListCtrl*) this -> FindWindowById (ID_LIST));

  int index = list -> GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);

  if (list -> GetEditControl ())
  list->EndEditLabel(true);
  else if (index != -1)
  {
  list -> EditLabel (index);
  }

}

Both pieces of code call EditLabel function where the event for editing label (wxEVT_LIST_BEGIN_LABEL_EDIT) should be triggered however the binded method in my code does not get triggered while the code in the sample does get triggered.

I bind method in the event table the same way as in the sample: EVT_LIST_BEGIN_LABEL_EDIT (ID_LIST, GUI::OnEditListLabel)

Sample: EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit)

I probably miss something very trivial, but can't seem to figure it out. Any ideas?

Cheers, Vilius


Solution

  • Have to add wxLC_EDIT_LABELS style when creating instance of the wxListCtrl to enable editing of the labels which in return triggers event EVT_LIST_BEGIN_LABEL_EDIT and EVT_LIST_END_LABEL_EDIT.