Reputation: 347
so i made a simple program in mfc dialog in c++ which has an add button, a remove button, a listbox, and an edit box. i want to be able to type something into the editbox, then click the add button and it will get added to the listbox. but i am getting this error:
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'CEdit' (or there is no acceptable conversion)
here is the code for the add button:
void CtestDlg::OnBnClickedMybuttonadd()
{
CString str;
UpdateData();
str = m_myEditBox;
UpdateData(FALSE);
m_myListBox.AddString(str);
}
Upvotes: 0
Views: 545
Reputation: 50912
The type of m_myEditBox is CEdit.
You cannot assign a string from a CEdit objet by using the = operator.
Try this:
m_myEditBox.GetWindowText(str);
instead of:
str = m_myEditBox;
Upvotes: 1
Reputation: 4668
There is no off the helf conversion b/n CEdit
to CString
, please use this
int lc = m_myEditBox.GetLineCount();
CString strLine;
CStringArray arr;
for (int i = 0; i < lc ; i++)
{
int len = m_myEditBox.LineLength(m_myEditBox.LineIndex(i));
m_myEditBox.GetLine(i, strLine.GetBuffer(len), len);
strLine.ReleaseBuffer(len);
m_myListBox.Add(strLine);
}
Upvotes: 0