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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting text from combo box control

Getting text from combo box control

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialcomquestionlearning
5 Posts 3 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.
  • 7 Offline
    7 Offline
    7stud
    wrote on last edited by
    #1

    Hi, I’ve been playing around with the Beginner’s DialogBox One tutorial on this site: http://www.codeproject.com/dialog/dialogapptute.asp and I was wondering how to get the text from a combo box. In the tutorial, we populated the IDC_TITLE combo box with some data(using the Data tab of the Combo Box Properties we accessed by right clicking the control): Mr. Mrs. Dr. Ms. Then, for the combo box we added a member variable called m_nTitle, Category: Value, Type: int. I assume that when UdateData(TRUE) is executed, the integer position of the Title chosen by the user is transferred into m_nTitle. Is there a way to use m_nTitle to get the corresponding text from the combo box? I thought maybe if I added a Category: Control variable to IDC_TITLE, like m_controlTitle, then I could use m_controlTitle and m_nTitle to get the text, something like this: CString strTitle; strTitle = m_controlTitle.GetText(m_nTitle); but there doesn’t seem to be a method of the ComboBox class that will do that. In the tutorial, it says to do this: CString strTitle; int nIndex; nIndex = GetDlgItemText(IDC_TITLE, strTitle); but that just completely ignores the m_nTitle variable we created for the control.

    L 1 Reply Last reply
    0
    • 7 7stud

      Hi, I’ve been playing around with the Beginner’s DialogBox One tutorial on this site: http://www.codeproject.com/dialog/dialogapptute.asp and I was wondering how to get the text from a combo box. In the tutorial, we populated the IDC_TITLE combo box with some data(using the Data tab of the Combo Box Properties we accessed by right clicking the control): Mr. Mrs. Dr. Ms. Then, for the combo box we added a member variable called m_nTitle, Category: Value, Type: int. I assume that when UdateData(TRUE) is executed, the integer position of the Title chosen by the user is transferred into m_nTitle. Is there a way to use m_nTitle to get the corresponding text from the combo box? I thought maybe if I added a Category: Control variable to IDC_TITLE, like m_controlTitle, then I could use m_controlTitle and m_nTitle to get the text, something like this: CString strTitle; strTitle = m_controlTitle.GetText(m_nTitle); but there doesn’t seem to be a method of the ComboBox class that will do that. In the tutorial, it says to do this: CString strTitle; int nIndex; nIndex = GetDlgItemText(IDC_TITLE, strTitle); but that just completely ignores the m_nTitle variable we created for the control.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Off hand, I would have to say try GetWindowText() and see if that will work for you. Artificial intelligence is no match for natural stupidity.

      7 1 Reply Last reply
      0
      • L Lost User

        Off hand, I would have to say try GetWindowText() and see if that will work for you. Artificial intelligence is no match for natural stupidity.

        7 Offline
        7 Offline
        7stud
        wrote on last edited by
        #3

        Hi, Thanks for the response. In the tutorial, this works: CString strTitle; int nIndex; nIndex = GetDlgItemText(IDC_TITLE, strTitle); The function you posted, GetWindowText() seems to be of the same form as GetDlgItemText() in that it completely ignores the value of the control, m_nTitle, that we already have. I wondered what was the point of creating a variable to hold the value of the combo box control, if it wasn't going to be used. In turn, I wondered if there is a way to get the text from a combo box using the value of the control.

        P 1 Reply Last reply
        0
        • 7 7stud

          Hi, Thanks for the response. In the tutorial, this works: CString strTitle; int nIndex; nIndex = GetDlgItemText(IDC_TITLE, strTitle); The function you posted, GetWindowText() seems to be of the same form as GetDlgItemText() in that it completely ignores the value of the control, m_nTitle, that we already have. I wondered what was the point of creating a variable to hold the value of the combo box control, if it wasn't going to be used. In turn, I wondered if there is a way to get the text from a combo box using the value of the control.

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          CComboBox::GetLBText(int _nIndex_, CString& _rString_) const;


          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

          7 1 Reply Last reply
          0
          • P PJ Arends

            CComboBox::GetLBText(int _nIndex_, CString& _rString_) const;


            "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

            7 Offline
            7 Offline
            7stud
            wrote on last edited by
            #5

            I spent several minutes reading your sig and wondering what the heck you were trying to tell me before I noticed the line with the method. Thanks for taking the time to help a beginner.

            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