?
Solved

Dialog Drop Down AddString Not Working

Posted on 2003-03-31
12
Medium Priority
?
1,120 Views
Last Modified: 2013-11-20
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
Comment
Question by:DougC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 8243918
Hi DougC,

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

hope that helps,

ZOPPO
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 8243958
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
 
LVL 3

Accepted Solution

by:
Nosfedra earned 160 total points
ID: 8244418

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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 1

Author Comment

by:DougC
ID: 8248411
It worked!!!! I moved the AddStrings to the DoDataExchange function.

Thank You
Doug
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 8251521
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
 
LVL 3

Expert Comment

by:Nosfedra
ID: 8251566
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
 
LVL 31

Expert Comment

by:Zoppo
ID: 8251611
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
 
LVL 3

Expert Comment

by:Nosfedra
ID: 8251722
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
 
LVL 31

Expert Comment

by:Zoppo
ID: 8251865
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
 
LVL 1

Author Comment

by:DougC
ID: 8286972
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
 
LVL 1

Author Comment

by:DougC
ID: 8287648
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
 
LVL 1

Author Comment

by:DougC
ID: 8288048
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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question