wxTreeCtrl EditLabel in OnEndLabelEdit

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
lskaa
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Dec 23, 2011 12:37 pm

wxTreeCtrl EditLabel in OnEndLabelEdit

Post by lskaa » Fri Dec 23, 2011 12:57 pm

Hi All,

I am playing treectrl sample from 2.8.11 package.I have added EditLabel after event.Veto(). I can edit the label but hitting enter is no effect. Kindly have your advice. Thanks SK.

void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event)
{
wxLogMessage(wxT("OnEndLabelEdit"));

// don't allow anything except letters in the labels
if ( !event.GetLabel().IsWord() )
{
wxMessageBox(wxT("The new label should be a single word."));
event.Veto();
EditLabel(event.GetItem());
}
}

tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Re: wxTreeCtrl EditLabel in OnEndLabelEdit

Post by tbreina » Fri Dec 23, 2011 4:16 pm

Code: Select all

void MyTreeCtrl::OnEndLabelEdit(wxTreeEvent& event)
{
wxLogMessage(wxT("OnEndLabelEdit"));

// don't allow anything except letters in the labels
if ( !event.GetLabel().IsWord() )
{
wxMessageBox(wxT("The new label should be a single word."));
EditLabel(event.GetItem());

event.Veto();

}
}
I think event.Veto() has to go last. Otherwise, it skips the rest of your code.

-Tony
Everybody's got something to hide except for me and my monkey.

lskaa
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Dec 23, 2011 12:37 pm

Re: wxTreeCtrl EditLabel in OnEndLabelEdit

Post by lskaa » Fri Dec 23, 2011 11:04 pm

Have tried. Same.

Also, remove event event.Veto() and use event.Skip(). Still no effect.

Thanks.
SK

tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Re: wxTreeCtrl EditLabel in OnEndLabelEdit

Post by tbreina » Sat Dec 24, 2011 2:40 am

What are you trying to do with the EditLabel(event.GetItem())? That is, what's the effect of your change?

Currently, your code is being executed within the if-then scope. So it will only run when the user has incorrectly changed the label to a non-word. The event.Veto() changes the label back to the original value.

Are you sure you want to add your EditLabel at that point in the code?

-Tony
Everybody's got something to hide except for me and my monkey.

lskaa
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Dec 23, 2011 12:37 pm

Re: wxTreeCtrl EditLabel in OnEndLabelEdit

Post by lskaa » Sat Dec 24, 2011 11:21 am

Actually, my use case is
1) Rename treeview label (OnBeginLabelEdit)
2) Enter 'ABC%' and hit enter (OnEndLabelEdit)
3) 'ABC%' is not word (!event.GetLabel().IsWord()) and allow to edit again (EditLabel(event.GetItem()))
4) Correct 'ABC' and hit enter <-- no respond

BTW Merry Christmas.... SK

tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Re: wxTreeCtrl EditLabel in OnEndLabelEdit

Post by tbreina » Sun Dec 25, 2011 12:51 am

Ok, I see now.

You might want to try posting this on the C++ Development forum (http://forums.wxwidgets.org/viewforum.php?f=1). You're more likely to get a correct response since the question is a wxWidgets one, not a wxDev-C++ specific one.

-Tony
Everybody's got something to hide except for me and my monkey.

Post Reply