Link to home
Start Free TrialLog in
Avatar of DougC
DougC

asked on

Dialog Drop Down AddString Not Working

Hi:

I have:

.H

CComboBox          m_power;

OnInitDialog()

m_power.AddString("Power Off");
m_power.AddString("Power On")
m_power.SetCurSel (0);
UpdateData();
return TRUE;

DoDataExchange(pDX);
DDX_Control(pDX, IDC_POWER, m_power);

I don't see them displayed, except when I do Test Dialog and not when I run the app. Any ideas? Waht am I missing?

Thanks,
Doug

Avatar of Zoppo
Zoppo
Flag of Germany image

Hi DougC,

call UpdateData( FALSE ); instead of UpdateData();

hope that helps,

ZOPPO
hm ... sorry ... maybe last was a wrong guess ... at least in
my testapp it works an anyway (with ot without UpdateData with
TRUE or with FALSE).

Is the combo-box loaded from resource or created at runtime?
ASKER CERTIFIED SOLUTION
Avatar of Nosfedra
Nosfedra

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DougC
DougC

ASKER

It worked!!!! I moved the AddStrings to the DoDataExchange function.

Thank You
Doug
And you're sure that's a good solution ... I tried it in my
testapp and the strings now are added with every call to
UpdateData();
Indeed zoppo. I am missing there one line:

m_power.ResetContent();

which deletes all the strings in the combo box.

If using DoDataExchange for initialization, one should have to follow the reason for this method is called by the framework.
This method is called after each UpdateData.

The guys designing this were having in mind that when calling UpdateData, one should want to modify the interface contents from the changed program data, hence it would be better to have in the DoDataX... initializations that are somewhat dynamic, rather than static.
One shouldn't call UpdateData if there is no need to.

But nevertheless, thanks for pointing the situation to this thread.

Regards,
--Razvan
Well, but I think it would be better to find the cause for the
problem than doing a workaround ...

It's not the default behavior of a MFC dialog with a combo-box
subclassed that 'combo.AddString()' doesn't add the string.
There must be a bug anywhere ...

But, anyway it's DougC's decision...

ZOPPO
Duh... I tried adding strings the way Doug did and it worked here too...

I wonder if this isn't a SP issue (I have sp5 installed). Some time ago, I remember having this sort of problems with combo boxes which refused to show added data.

I got bored of trying and used the first solution I proposed (GetDlgItem... + add the strings).


Maybe we should share the points on this ;-)
hm ... I never had problems like these and I use MSVC since
version 4.0.

If DougC is satisfied with the solution you provided it's ok.
Avatar of DougC

ASKER

Can someone give me a more complete example of the first example without DDX? In other words what goes in the .h and what goes in InitDialog, and what goes in OnCbnSelchange? What if I want to set the selection to a specific item in the list.

Thanks,
Doug

P.S. The DDX UpdateData solution worked until I tried setting the selection and that did not work, so I am trying to get rid of DDX. So what I need is an example of a combobox without DDX.
Avatar of DougC

ASKER

Can someone give me a more complete example of the first example without DDX? In other words what goes in the .h and what goes in InitDialog, and what goes in OnCbnSelchange? What if I want to set the selection to a specific item in the list.

Thanks,
Doug

P.S. The DDX UpdateData solution worked until I tried setting the selection and that did not work, so I am trying to get rid of DDX. So what I need is an example of a combobox without DDX.
Avatar of DougC

ASKER

Soemhow, I need to put the CComboBox *m_input =(CComboBox*)GetDlgItem(IDC_INPUT); where it can be used in more than one function (e.g. in OnInitDialog and in OnSelChanged, etc.

Doug