Select the whole text on focus

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Select the whole text on focus

Hi Vadim,

I have a dialog with some text fields on it, and i want the text to be selected when the ctrl gain focus. So i implemented this little game (select on focus) like this:

void OnSetFocus(wxFocusEvent& event)
    wxWindow* focus = wxWindow::FindFocus();

    if (focus)
        wxTextCtrl* txtCtrl = wxDynamicCast(focus, wxTextCtrl);

        if (txtCtrl)
                if (txtCtrl->HasFocus())
                    wxSafeYield( txtCtrl, true );


Is this the right way to go ?

Note that if i remove wxSafeYield() call, the text got selected till the cursor where i actually clicked inside the ctrl which may result in the text got partially selected !!

Please read before posting.

To unsubscribe, send email to [hidden email]
or visit