How to modify combo box displayed selection without changing available selections.

I have a dialog which contains a combo box.
The combo box has several items in its drop down list.
One item in the drop down list selects an option requiring the user to input a number.
If the user selects this item from the combo box drop down list, a modal pop up will read the number.
At this point, the combo box displays the text corresponding to the user's selection and the application has stored the number read from the pop up into a variable.

We want to change the the text displayed in the combo box selection to contain the number read from the popup WITH OUT changing the text in the drop down selections.

The question is:
Is there some method the C++ application can use to change the displayed combo box selection without modifying the text in the drop down text, just change the text displayed in the edit box area of the combo box?

I can use GetDlgItemText() to read combo box displayed selection, but SetDlgItemText() doesn't change the combo box display.

Being able to do this would keep the user informed of what option was chosen as well as display the value entered without disturbing possible future drop down list choices and would not require extra screen dialog space.

Thanks for your help.
dfftAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Sending a 'CB_SETITEMDATA' (http://msdn.microsoft.com/en-us/library/windows/desktop/bb775909%28v=vs.85%29.aspx) to the Combo Box allows you to do that. E.g.

TCHAR buf[32];
_stprintf(buf,_T("New Value: %d", nVal");
int nVal = 42; // the one you got from the user
SendMessage(GetDlgItem(hDlg,IDI_MYCOMBOBOX),CB_SETITEMDATA,INDEX_OF_VALUE,(LPARAM)buf);

Open in new window

0
dfftAuthor Commented:
I appreciate your prompt response to my question.

Am I incorrect in understanding that CB_SETITEMDATA message will replace the drop down list string enumerated by the value in INDEX_OF_VALUE with the string contained in buf?

That would change the contents of the drop down list and leave the text displayed in the text box unchanged?

If that is correct, I am asking how to do the opposite. After the user has selected an item from the drop down list, I want to change the contents of the text box and leave the contents in the drop down list unchanged.

This would allow the user to see in the combo box's text box which option was chosen from the drop down list AND what value he supplied without modifying future possible selections from the drop down list.

I apologize for wording my question so badly.

Maybe I should be asking if there is a way to obtain the ID of the text box in the combo box control so that I can send commands to it directly without disturbing the drop down list?

Should I be rolling my own combo box? Not sure I have the skills to do that in the time frame I have to work on this.

Thanks
0
jkrCommented:
>>That would change the contents of the drop down list and leave the text displayed in the
>>text box unchanged?

Wait a minute - if you are changing the value of the selected item the changes should be reflected in both places. Why not giving it a try, since it is basically one line of code...
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

dfftAuthor Commented:
Thanks
Previously, I was wrong about CB_SETITEMDATA, it will change the value associated with an entry in the drop down list, not change the contents of the drop down list.

>>Wait a minute - if you are changing the value of the selected item the changes should be >>reflected in both places. Why not giving it a try, since it is basically one line of code...

If this is true, then I can't change the contents of the combo box's text box without changing the contents of the drop down list?

I think you are writing that if, say the 5th item in a drop down list is selected and displayed in the text box, that if I change the contents of the 5th item in the drop down list, then the contents of the text box will automatically change to what the 5th (previously selected) item in the drop down list has been changed to? Perhaps when the window is redrawn or updated?

What I have is a drop down list of five items.
0. Use Option A
1. Use Option B
2. Use Option C N times
3. Use Option D
4. Use Option E M times

If the user chooses "Use Option C N times" then "Use Option C N times" will be displayed in the text box when the drop down list rolls up. and the application code pops up a dialog asking for the value of N.

The thought was that if the text box in the combo box control displayed
 "Use Option C 23 times" (if the user responded to the pop up with 23), then the user would see what option was chosen in the main dialog while the user went about selecting other controls.
If the user later came back to the combo box, the drop down list would still display
" Use Option C N times" as item 2 and be a reminder that if item 2 is chosen, a number will be required.

I wasn't considering that the selection in the  text box being displayed in the combo box control might automatically be redrawn some how and overwrite whatever I may have managed to put there.

So, I'll give it up and add another item to the main dialog which is already crowded.

Thanks for your patience and help.
0
sarabandeCommented:
you could use an edit field, a button, and a listbox to simulate a combobox where actually you have 3 controls which were independent.

or, probably better, when the user selects the entry 'Use Option n times' you move a former hidden edit field (or spin buttons) directly to the place where the cursor currently is and allow the user to set 'n' that way. after that you could display the 'n' in a separate field. i think that changing the text both in the drop-down list and in the edit part of the combobox also would be an acceptable solution.

Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dfftAuthor Commented:
Actual solution was to dynamically add an additional item to the drop down list formatted with the desired text  using CB_ADDSTRING message and then using CB_SETCURSEL message to cause the new text to appear in the combo box test box.

But:
Needed to add code for OnCbnDropdown and OnCbnSelendcancel mesages to handle the logic to restore the original dropdown list if the user selected it again to change values or to reinstate modified the dropdown list if user selected the dropdown list again but chose to cancel.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.