Getting text from combo box control
-
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.
-
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.
-
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.
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.
-
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.
-
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!