Best way to change dialog's content depending on user's choice 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
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Best way to change dialog's content depending on user's choice

Post by rudolfninja »

Hi,
I've got dialog with table (lets say with two columns: name and type). Depending on the type of selected row I need to display options available for this type. If type of selected item is A I need to display following options:
first_choice.png
first_choice.png (6.26 KiB) Viewed 953 times
If the type is B then:
second_choice.png
second_choice.png (6.36 KiB) Viewed 953 times
So the question, what is the best way to implement this feature?
For now I only have two ideas:
1) Create two wxSizers and place needed controls on each sizer. Place these sizers at one position and just show/hide on of the sizers depending on type.
But this approach has two drawbacks:
a) I've got one wxRadioButton object for "None"-button and one for "Password"-button. However, as I know, I can't place one control on two different sizers.
b) These sizers are placed on another sizer (main sizer of the dialog). And, as I know, I can't place two sizers at one position inside of another sizer.

2) Create one sizer and flush it and then create controls and place them in needed order on every row selection change.
This variant, as it seems to me, is full of drawbacks, so I even don't consider it.

Could you please advise any better variants to handle this situation?

P.S. programming language: C++; wxWidgets 3.1.1
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: Best way to change dialog's content depending on user's choice

Post by Manolo »

My personal opnion is to show to the user the most of info. I prefer to put all controls related to a task in the same panel, disabling those not needed because of some option. Sometimes this is too much "heavy" visual load.

Then, a on-fly changing panel may suffix. As you already know, this can accomplished by two sizers.
Each sizer has its own controls (or other sizers). No repetitions. Two "same" control are defined by two different instances, like when you have two wxButton's at the same time in a sizer.

Then, a simple wxSizer::Hide/Show in the proper sizer does the magic.
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Re: Best way to change dialog's content depending on user's choice

Post by rudolfninja »

Thanks for the answer.
If we talk about "two sizers" solution, then how can I place these two sizers in the one position of external (parent) sizer? As a parent sizer I use wxBoxSizer(wxVERTICAL) and I don't know how to add two sizers on the one position...actually, I don't need to place the sizers in the same position because after wxSizer::Hide/Show call parent sizer will adjust automatically, right?
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Best way to change dialog's content depending on user's choice

Post by doublemax »

You can put them both in the same sizer. The hidden one will be ignored by the layout process.

I personally prefer to put all related items onto a separate wxPanel and show/hide the panels instead of the sizers. But both versions should do the same.
Use the source, Luke!
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Re: Best way to change dialog's content depending on user's choice

Post by rudolfninja »

Ok, thank you, guys.
Will try to implement the solution with two sizers.
Post Reply