Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1144
  • Last Modified:

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

0
DougC
Asked:
DougC
  • 5
  • 4
  • 3
1 Solution
 
ZoppoCommented:
Hi DougC,

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

hope that helps,

ZOPPO
0
 
ZoppoCommented:
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?
0
 
NosfedraCommented:

One certain way to accomplish what you want is:
CComboBox *cb = (CComboBox *)GetDlgItem(IDC_YOUR_COMBO)...
and use that pointer to do the adding.

But since you are using DDX, try to move the AddString stuff in the DoDataExchange function:
if (pDX->m_bSaveAndValidate)
{  // do something on exiting the dialog here
}
else
{ m_power.AddString("Power Off");
  m_power.AddString("Power On")
  m_power.SetCurSel (0);
}

Hth...
--Razvan
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
DougCAuthor Commented:
It worked!!!! I moved the AddStrings to the DoDataExchange function.

Thank You
Doug
0
 
ZoppoCommented:
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();
0
 
NosfedraCommented:
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
0
 
ZoppoCommented:
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
0
 
NosfedraCommented:
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 ;-)
0
 
ZoppoCommented:
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.
0
 
DougCAuthor Commented:
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.
0
 
DougCAuthor Commented:
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.
0
 
DougCAuthor Commented:
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
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now