Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Find out what was selected in Combo Box

How to Find out what was selected in Combo Box

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++visual-studiotutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Larry Mills Sr
    wrote on last edited by
    #1

    During the creation of my Combo Box I entered the data into it for selection of the User. How do I find out what the User selected? Please provide some code please.(VS 6.0 and VS 2008 C++) A C++ programming language novice, but striving to learn

    H M D 3 Replies Last reply
    0
    • L Larry Mills Sr

      During the creation of my Combo Box I entered the data into it for selection of the User. How do I find out what the User selected? Please provide some code please.(VS 6.0 and VS 2008 C++) A C++ programming language novice, but striving to learn

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Do you want to get value or focus on combobox?

      1 Reply Last reply
      0
      • L Larry Mills Sr

        During the creation of my Combo Box I entered the data into it for selection of the User. How do I find out what the User selected? Please provide some code please.(VS 6.0 and VS 2008 C++) A C++ programming language novice, but striving to learn

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        When the user changes the selected item, the parent will receive a CBN_SELCHANGE notification (in a WM_COMMAND message). In response to that notification, or at some other time you need the selected item from the combo box, you could do something like this:

        LRESULT SelectedIndex = SendMessage(hwndComboBox, CB_GETCURSEL, 0, 0);
        if (CB_ERR != SelectedIndex)
        {
        LRESULT StringLength = SendMessage(hwndComboBox, CB_GETLBTEXTLEN, SelectedIndex, 0);
        TCHAR *pSelectedString = new TCHAR[StringLength + 1];
        SendMessage(hwndComboBox, CB_GETLBTEXT, SelectedIndex, (LPARAM)pSelectedString);
        //...
        //... do something with the string ...
        //...
        delete[] pSelectedString;
        }

        All Windows controls have associated messages used to manipulate them. Unless you have them all memoized, I recommend keeping a link to this: Windows Controls[^] or know where to find it in your local documentation.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • L Larry Mills Sr

          During the creation of my Combo Box I entered the data into it for selection of the User. How do I find out what the User selected? Please provide some code please.(VS 6.0 and VS 2008 C++) A C++ programming language novice, but striving to learn

          D Offline
          D Offline
          ddspliting
          wrote on last edited by
          #4

          Hey! Well i dun ve visual studio 08. But i can provide you a help in visual studio 6.0. Now as you have already entered data to the combo box.Add new variable for the Combo Box in class wizard. it can be of type VALUE or CONTROL. Let it be VALUE and type CString. This variable will hold the data present in the Combo Box.Let the variable is ComboBox_Variable. Now to check what user has selected, you can put a simple event in your program which will help in finding what user has selected from the box. so you can add a button which will show a simple messagebox depending on the combo box data. Like a button named "Message". Add an event handler for it and you can use the following code. CString example; example = ComboBox_Variable; if(example=="Data-1") MessageBox("Data-1 selected by user"); else if(example=="Data-2") MessageBox("Data-2 selected by user"); You can use switch statement too! I hope Combo Box will be clear to you now!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups