c++wxwidgetstextctrl

How to insert a character to a text control in wxwidgets from the code itself?


I have this textctrl

FTextCtrl = new wxTextCtrl(parent, wxID_ANY, _("Text"), wxPoint(20, 20), wxDefaultSize, wxTE_CENTRE | wxTE_PROCESS_ENTER, wxDefaultValidator, _T("ID_TC"));

For this control based on the programming logic, I want to insert a editable character into the text field. How can we do the same?


Solution

  • To insert text at the given position, you should use SetSelection() to set the insertion point (by creating an empty selection at the desired position) and then WriteText(). Of course, if you just want to append the text, you could use AppendText() directly.

    Finally, you may decide to just use ChangeValue() to replace the entire value instead of fiddling with these functions.