Click here to Skip to main content
15,891,787 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Gentle people,
Could somebody please give me a push in the right direction?
There is an array of hundreds of strings to be filled from a list of thousands. Hence I thought it'd be a good idea to have a single combobox with the thousands of strings in the list and move it at random onto the elements of the array currently displayed on the screen and fill the element selected from the combobox list.

Well, all of this works as designed except for one thing - no matter what I do (and I have tried a lot), the combobox always shows the last item selected from the combobox list in the edit part, but when I select the next element I want to see the current contents of this element, not that of the last one.

Naively I assumed a simple SETTEXT to the edit part of the combobox would do the job. Unfortunately it does not.

Any ideas?
Posted

1 solution

As far as I know, there's 2 ways to go about this (I think they're functionally identical):

1. Use the CB_SELECTSTRING message
2. Use the CB_FINDSTRING/CB_FINDSTRINGEXACT + CB_SETCUSEL pair.

C++
SendMessage(comboHwnd, CB_SELECTSTRING, 0, (LPARAM)buffer);


or

C++
index = SendMessage(comboHwnd, CB_FINDSTRING, -1, (LPARAM)buffer);
if (index != CB_ERR)
    SendMessage(comboHwnd, CB_SETCURSEL, index, 0);
 
Share this answer
 
Comments
Sandeep Mewara 15-Jun-12 1:24am    
My 5!
Ernst G. Gruber 15-Jun-12 7:08am    
Thanks a lot for the answer! The FINDSTRING method you mentioned was my plan B, but seemed to be not very elegant, for all the information necessary is already available. Additionally one needs an empty entry in the list to take care of empty elements in the array ...
Well, you can't win them all! Thank you again for your help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900