CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Posts
    344

    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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured