Page 1 of 1

wxTextCtrl Selected Text

Posted: Thu Oct 22, 2009 6:50 am
by miclus
Hi. How do you make it so text stays selected when the contents of a text control change? Every time the contents change, my selection gets unselected...

Posted: Thu Oct 22, 2009 10:55 am
by spectrum
i would try to reselect all, inside the "change" event.

wxTextCtrl documentation,
EVT_TEXT(id, func),
wxTextCtrl samples.


Posted: Tue Nov 24, 2009 6:44 pm
by miclus
Ok, I traced it to this function:

Code: Select all

void wxRichTextCtrl::DoWriteText(const wxString& value, int flags)
    wxString valueUnix = wxTextFile::Translate(value, wxTextFileType_Unix);

    GetBuffer().InsertTextWithUndo(m_caretPosition+1, valueUnix, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);

    if ( flags & SetValue_SendEvent )

Since AppendText doesn't use the flags, it can only be that InsertTextWithUndo line.

Any ideas how to stop it from deselecting selected text?

Posted: Tue Nov 24, 2009 7:42 pm
by doublemax
That the selection gets lots when changing/adding text is pretty much standard behavior in any textcontrol in know of. I guess your only chance is to store/restore the selection yourself after adding text, but you might get an ugly flicker.

Posted: Tue Nov 24, 2009 8:48 pm
by miclus
Yeah, that's what I did. Works out ok. Thanks.