Click to See Complete Forum and Search --> : How to obtain edited string from CComboBox


Soso
April 12th, 1999, 08:40 AM
I've created the combobox with the style CBS_DROPDOWN. I want to achieve the functionality, where the user can type new string in the edit control of the combobox and when he presses the Enter key, the new string will be added to the combobox list. The problem is, that I don't know how to obtain the typed string. GetWindowText() doesn't work on combobox, neither the GetLBText() function, since the GetCurSel() returns -1 (the string is not in the combobox yet, so I don't have current selection yet...).

Thank you,
soso.

Thomas Wiesinger
April 12th, 1999, 11:51 AM
HI!

I think of 2 possibilities ->

a. CComboBoxEx has member function "GetEditCtrl" to retrieve it's edit control.

b. CComboBox::Copy copies the text in the edit ctrl to the clipboard, maybe you can use it from there...

Hope this helps,

Thomas

Soso
April 13th, 1999, 02:25 AM
Please where can I get the class CComboBoxEx ? Never heard about it before...

Thank you,
Soso.

Thomas Wiesinger
April 13th, 1999, 02:57 AM
I've installed MSVC6.0 and there's a CComboBoxEx, so it's maybe not available if using MSVC 5.0. Nevertheless it's also for CComboBox possible to retrieve the child edit control attached to it, though, it's a bit more work to do, but I guess FindWindow() should do the work for you.

Regards, Thomas

Hussam
April 13th, 1999, 10:00 AM
Well, GetWindowText should work fine with your ComboBox.
The problem you may have is for sure related to something else.

GetWindowText works with all CWnd derived controls.

I tried it and am using it with many ComboBoxes with different styles and it works fine. On the other hand SetWindowText does not work with all CWnd derived classes.
Are you sure that your handling for ENTER is correct?

ex.
CString sComboTxt;
m_Combo.GetWindowText(sComboTxt);
AfxMessageBox(sComboTxt);Good Luck
Hussam


hussam.ahmad@delfidata.no