[英]error with button for adding items to listbox
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. 所以我在c ++的mfc对话框中制作了一个简单的程序,其中有一个添加按钮,一个删除按钮,一个列表框和一个编辑框。 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) 错误1错误C2679:二进制'=':未找到采用'CEdit'类型的右侧操作数的运算符(或没有可接受的转换)
here is the code for the add button: 这是添加按钮的代码:
void CtestDlg::OnBnClickedMybuttonadd()
{
CString str;
UpdateData();
str = m_myEditBox;
UpdateData(FALSE);
m_myListBox.AddString(str);
}
The type of m_myEditBox is CEdit. m_myEditBox的类型为CEdit。
You cannot assign a string from a CEdit objet by using the = operator. 您不能使用=运算符从CEdit对象中分配字符串。
Try this: 尝试这个:
m_myEditBox.GetWindowText(str);
instead of: 代替:
str = m_myEditBox;
There is no off the helf conversion b/n CEdit
to CString
, please use this 没有从b / n CEdit
到CString
的临时转换,请使用此
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.