Solved

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

Posted on 2014-01-16
6
1,216 Views
Last Modified: 2014-01-20
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.
0
Comment
Question by:dfft
[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
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39786203
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
 

Author Comment

by:dfft
ID: 39786695
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
 
LVL 86

Assisted Solution

by:jkr
jkr earned 250 total points
ID: 39786722
>>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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dfft
ID: 39786908
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
 
LVL 34

Accepted Solution

by:
sarabande earned 250 total points
ID: 39787799
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
 

Author Comment

by:dfft
ID: 39795136
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

717 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