Automatically change choices numbers in wxChoice

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
marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

Automatically change choices numbers in wxChoice

Post by marcusbarnet »

I load the content retrieved from a MySQL database to populate choices in several wxChoice controls.
I display each record from the database as a choice for the wxchoice control and it works fine.

The problem is that the number of records can increase and so it can exceed the number of default choices that I set for the wxChoice.
For the moment, I tried to set an higher number of choices in this way:

Code: Select all

    Choice19 = new wxChoice(this, ID_CHOICE22, wxPoint(584,424), wxSize(224,104), 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE22"));
    Choice19->SetSelection( Choice19->Append(_("Esercizio")) );
    Choice19->Append(_("--"));
    Choice19->Append(_("--"));
    Choice19->Append(_("--"));
    Choice19->Append(_("--"));
Is there a way to automatically add/increase the choices in a wxChoice control?
For example, in the above code, if I retrieve more than 5 items from the database, I will get an error during the compiling because there are not enough pre-loaded choices.

I'm using wxSmith, CodeBlocks, C++, Windows 10, WxWdigets 3.1
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Automatically change choices numbers in wxChoice

Post by doublemax »

You can call Append() or Insert() to add individual items, or call Clear() and Set() to refill it completely.

https://docs.wxwidgets.org/trunk/classw ... ainer.html
Use the source, Luke!
Post Reply