To SelectNone() a wxTextCtrl on startup. Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
AshtonC1
Earned some good credits
Earned some good credits
Posts: 100
Joined: Wed Feb 18, 2015 4:56 pm

To SelectNone() a wxTextCtrl on startup.

Post by AshtonC1 »

I'd like to remove selected/highlited attribute from default text in a wxTextCtrl on startup.

What I have tested and is working under a wxButton test is:

Code: Select all

btnClose->SetFocus();
txtRecip->SelectNone(); //Removes selection from existing text
    
But using this method with OnActivate, does not remove the selection from the text box.:

Code: Select all

void email_GUIFrame::OnActivate(wxCommandEvent& event)
{
  btnClose->SetFocus();
    txtRecip->SelectNone();
}
Its a timing issue I think, so the frame's controls are not settled, before my method hits maybe?
Will I have to call a timer? Would still need to know when frame is Ready.

Edit: HasFocus() didn't work either.
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: To SelectNone() a wxTextCtrl on startup.

Post by jgrzybowski »

Perhaps it is native behaviour of single line text control in operating system. Try to set up for your wxTextCtrl object style: wxTE_MULTILINE. Regards, Jarek
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: To SelectNone() a wxTextCtrl on startup.

Post by ONEEYEMAN »

Hi,
Most likely the window is not active yet and therefore the code fails.
Try CallAfter().

Thank you.
AshtonC1
Earned some good credits
Earned some good credits
Posts: 100
Joined: Wed Feb 18, 2015 4:56 pm

Re: To SelectNone() a wxTextCtrl on startup.

Post by AshtonC1 »

Jarek,
Setting up the wxTextCtrl object style: wxTE_MULTILINE solved it.

Thanks.
Post Reply