Programmatically change combobox
I need to update a combobox with a new value so it changes the reflected text in it. The cleanest way to do this is after the combobox has been initialised and with a message.
So I am trying to craft a postmessage to the hwnd that contains the combobox.
So if I want to send a message to it, changing the currently selected item to the nth item, what would the PostMessage look like?
I am guessing that it would involve ON_CBN_SELCHANGE, but I can't get it to work right.
Thanks, G.
Re: Programmatically change combobox
Quote:
Originally Posted by grahamr (work)
I need to update a combobox with a new value ...
I am guessing that it would involve ON_CBN_SELCHANGE, but I can't get it to work right.
No, you guessed wrong.
CBN_SELCHANGE is a notification message being sent when the user changes the current selection in the list box of a combo box.
To change selection programmatically using pülain Win32 APIs you need to SendMessage CB_SETCURSEL (or CB_SELECTSTRING).
If you are using MFC (which would be more easier to develop) - then have a look at the CComboBox::SetCurSel, CComboBox::SelectString methods.