Home » Category » Microsoft Visual C & C++

Microsoft Visual C & C++: Combo box and Edit box

202| Sat, 09 Feb 2008 08:42:00 GMT| c_man| Comments (6)
Hi all,

Im new to MFC.
Now im learning how to use a combo box.

Question1:
I have a combo box with data value of (C++, Java, VB).
Whenever i choose one of the data value, I want the choosen data to be shown in an edit box.
How can i do it?

Below are part of my code.



void CComlistDlg::OnSelendokCombo1()
{
// TODO: Add your control notification handler code here
CString Answer;

Answer == m_combovalue; // m_combovalue is a CString that store value for Combo Box

m_ouput == Answer; // m_ouput is a CString that store value for Edit box
}

Thanks for the advance help

Rgds,
C_man

Keywords & Tags: combo, box, microsoft, visual c++, vc

URL: http://www.7prog.com/visual-c-c++/58476/
 
«« Prev - Next »» 6 helpful answers below.
I've never had any luck with declaring CString variables with Edit boxes. Maybe it's supposed to work, but I've always had to use SetDlgItemText and pass in the control ID. For more complex controls, such as Combo-boxes, I always declare m_combo as a CComboBox, and use the combo box functions to read and write.

Maybe it's supposed to work the other way, but sometimes it's easier to go around a problem than find a solution. :)

surfdabbler2 | Sun, 11 Nov 2007 00:23:00 GMT |

You can use CWnd::GetDlgItemText() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cwnd.3a3a.getdlgitemtext.asp) to retrieve the current text of a combo box or an edit box, and its counterpart CWnd::SetDlgItemText() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cwnd.3a3a.setdlgitemtext.asp) to set that text. So, if I'm understanding you right, then whenever you detect that the contents of the combo box have changed, you could do something like this:
CString strText;
GetDlgItemText(IDC_COMBO1, strText);
SetDlgItemText(IDC_EDIT1, strText);
where IDC_COMBO1 is the identifier for your combo box and IDC_EDIT1 is the identifier for the edit box. Hope this works... :)

smasherdevourer | Sun, 11 Nov 2007 00:24:00 GMT |

Hi guys,

Thanks for the help.

It works in VC++ but i tried to code it in eVC ++ 3.0.
In eVC the result shows abit of delay.

e.g in my combo box i have 3 data.
1.)hello
2.)my
3.)world

but when i choose hello the edit box will appear world instead of hello.

sorry for the weak english.
Thanks

c_man | Sun, 11 Nov 2007 00:25:00 GMT |

Hi C_man,
Probably your computer is just trying to complete the famous computer string "Hello World" :D.

ashwinrao | Sun, 11 Nov 2007 00:26:00 GMT |

Hi guyz,

CString strText;
GetDlgItemText(IDC_COMBO1, strText);
SetDlgItemText(IDC_EDIT1, strText);

Do i need to do a data conversion in eVC?

Thanks

c_man | Sun, 11 Nov 2007 00:27:00 GMT |

CString strText;
CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO1);
int nCurSel = pCombo->GetCurSel();
if(CB_ERR != nCurSel)
pCombo->GetLBText(nCurSel, strText);
SetDlgItemText(IDC_EDIT1, strText);

ovidiucucu | Sun, 11 Nov 2007 00:28:00 GMT |

Microsoft Visual C & C++ Hot Answers

Microsoft Visual C & C++ New questions

Microsoft Visual C & C++ Related Categories