MFC的程序,输入数据始终只能保存一条,随后输入会覆盖前面的,代码如下

来源:百度知道 编辑:UC知道 时间:2024/06/04 18:09:36
void CStuInputDlg::OnDispall()
{

UpdateData();
CString strSEX;
int nResult=GetCheckedRadioButton(IDC_MAN,IDC_WOMAN);
if(nResult==IDC_MAN) strSEX="男";
else strSEX="女";

m_strNAME.TrimLeft();
if (m_strNAME.IsEmpty())
{MessageBox("姓名不能为空!");}
m_strNO.TrimLeft();
if (m_strNO.IsEmpty())
{MessageBox("学号不能为空!");}

if(!m_strNAME.IsEmpty()&&!m_strNO.IsEmpty())
if(m_bDispAll)
m_DataList.Format("%-7s\t%-7s\t%-7s\t%-5d\t%-5d\t%-5d",m_strNAME,m_strNO,strSEX,m_Score1,m_Score2,m_Score3);
else
m_DataList.Format("%-7s\t%-7s\t%-7s",m_strNAME,m_strNO,strSEX);

UpdateData(FALSE);// 使用当前列表项所关联的内容显示在控件上
}

void CStuInputDlg::OnIuput()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
OnDispall();

}

不出意外的话,m_DataList被你声明为了CString,当然只记录一条输入。
你应该把m_DataList声明为链表类。如果它是成员变量,声明为CList;如果它是控件,声明为CListCtrl,再关联一个CList
CString cs;
cs.Format("%-7s\t%-7s\t%-7s",m_strNAME,m_strNO,strSEX);
m_DataList.AddTail(cs);

你那些成员变量都是什么类型的?尤其m_DataList是个什么东西?