问题现象:
1 点击“添加”,会在列表控件第0行中显示新增的记录,但是再次点击“添加”增加第12条,此时显示的依然是第11条的内容
2 先点击“显示记录”,再点击“添加”按钮添加第11项,只能显示第10项的记录
void CDatabase1View::OnButtonAdd()
{
// TODO: Add your control notification handler code here
m_recordlist.DeleteAllItems( );
CAddDlg dlg;
CString str1,str2,str3;
BOOL flag;
long nownum;
if(dlg.DoModal()==IDOK)
{
m_pSet->AddNew();
m_pSet->m_column1=atol(dlg.m_num);
m_pSet->m_column2=dlg.m_name;
m_pSet->m_column3=dlg.m_chinese;
m_pSet->m_column4=dlg.m_english;
m_pSet->m_column5=dlg.m_math;
m_pSet->m_column6=dlg.m_sport;
m_pSet->Update();
m_pSet->MoveLast();
//m_pSet->MoveNext();
m_pSet->m_totalnum=m_pSet->GetRecordCount();
str1.Format("%d",m_pSet->m_totalnum);
str1+="个记录数目";
MessageBox(str1);
CRecordsetStatus rStatus;
m_pSet->GetStatus(rStatus);
flag=rStatus.m_lCurrentRecord;
nownum=rStatus.m_lCurrentRecord;
if (flag)
{
MessageBox("总数确定!");
if (nownum==-2)
{
MessageBox("当前记录不确定!");
}
else if(nownum==-1)
MessageBox("当前记录太靠前");
else
{
str2.Format("%ld",nownum);
str2+="是当前记录锁定记录";
MessageBox(str2);
}
}
else
{
//str2.Format("%ld",nownum);
//str2+="是现在所在记录数";
//MessageBox(str2,"最后一行不确定");
MessageBox("总数不确定!");
if (nownum==-2)
{
MessageBox("当前记录不确定!");
}
else if(nownum==-1)
MessageBox("当前记录太靠前");
else
{
str2.Format("%ld",nownum);
str2+="是当前记录锁定记录";
MessageBox(str2);
}
}
str3.Format("%d",m_pSet->m_column1);
m_recordlist.InsertItem(0,str3);
m_recordlist.SetItemText(0,1,m_pSet->m_column2);
m_recordlist.SetItemText(0,2,m_pSet->m_column3);
m_recordlist.SetItemText(0,3,m_pSet->m_column4);
m_recordlist.SetItemText(0,4,m_pSet->m_column5);
m_recordlist.SetItemText(0,5,m_pSet->m_column6);
}
}
void CDatabase1View::OnButtonShow()
{
// TODO: Add your control notification handler code here
int i=0;
CString str,str1;
m_pSet->MoveFirst();
m_recordlist.DeleteAllItems( );
while(!m_pSet->IsEOF())
{
str.Format("%d",m_pSet->m_column1);
m_recordlist.InsertItem(i,str);
//str.Format("%d",m_pSet->m_column2);
m_recordlist.SetItemText(i,1,m_pSet->m_column2);
//str.Format("%d",m_pSet->m_column3);
m_recordlist.SetItemText(i,2,m_pSet->m_column3);
//str.Format("%d",m_pSet->m_column4);
m_recordlist.SetItemText(i,3,m_pSet->m_column4);
//str.Format("%d",m_pSet->m_column5);
m_recordlist.SetItemText(i,4,m_pSet->m_column5);
//str.Format("%d",m_pSet->m_column6);
m_recordlist.SetItemText(i,5,m_pSet->m_column6);
m_pSet->MoveNext();
i++;
}
m_pSet->m_totalnum=m_pSet->GetRecordCount();
str1.Format("%d",m_pSet->m_totalnum);
str1+="个记录数目";
MessageBox(str1,"记录总数");
}
请高手帮我看一下,新手啊!
5 个解决方案
#1
[img=http://my.csdn.net/ignewbie/album/detail/1266161][/img]
#2
如图
http://my.csdn.net/ignewbie/album/detail/1266161
http://my.csdn.net/ignewbie/album/detail/1266161
#3
楼主的程序逻辑,显示记录和添加怎么只有1个LISTCTRL呢??
#4
是的,但是我每次在显示前都清空啊,这样有影响吗
#5
这段代码其实不用看,是我为了让他显示总的记录和现在的当前记录是哪个而设立的
m_pSet->m_totalnum=m_pSet->GetRecordCount();
str1.Format("%d",m_pSet->m_totalnum);
str1+="个记录数目";
MessageBox(str1);
CRecordsetStatus rStatus;
m_pSet->GetStatus(rStatus);
flag=rStatus.m_lCurrentRecord;
nownum=rStatus.m_lCurrentRecord;
if (flag)
{
MessageBox("总数确定!");
if (nownum==-2)
{
MessageBox("当前记录不确定!");
}
else if(nownum==-1)
MessageBox("当前记录太靠前");
else
{
str2.Format("%ld",nownum);
str2+="是当前记录锁定记录";
MessageBox(str2);
}
}
else
{
//str2.Format("%ld",nownum);
//str2+="是现在所在记录数";
//MessageBox(str2,"最后一行不确定");
MessageBox("总数不确定!");
if (nownum==-2)
{
MessageBox("当前记录不确定!");
}
else if(nownum==-1)
MessageBox("当前记录太靠前");
else
{
str2.Format("%ld",nownum);
str2+="是当前记录锁定记录";
MessageBox(str2);
}
}
#1
[img=http://my.csdn.net/ignewbie/album/detail/1266161][/img]
#2
如图
http://my.csdn.net/ignewbie/album/detail/1266161
http://my.csdn.net/ignewbie/album/detail/1266161
#3
楼主的程序逻辑,显示记录和添加怎么只有1个LISTCTRL呢??
#4
是的,但是我每次在显示前都清空啊,这样有影响吗
#5
这段代码其实不用看,是我为了让他显示总的记录和现在的当前记录是哪个而设立的
m_pSet->m_totalnum=m_pSet->GetRecordCount();
str1.Format("%d",m_pSet->m_totalnum);
str1+="个记录数目";
MessageBox(str1);
CRecordsetStatus rStatus;
m_pSet->GetStatus(rStatus);
flag=rStatus.m_lCurrentRecord;
nownum=rStatus.m_lCurrentRecord;
if (flag)
{
MessageBox("总数确定!");
if (nownum==-2)
{
MessageBox("当前记录不确定!");
}
else if(nownum==-1)
MessageBox("当前记录太靠前");
else
{
str2.Format("%ld",nownum);
str2+="是当前记录锁定记录";
MessageBox(str2);
}
}
else
{
//str2.Format("%ld",nownum);
//str2+="是现在所在记录数";
//MessageBox(str2,"最后一行不确定");
MessageBox("总数不确定!");
if (nownum==-2)
{
MessageBox("当前记录不确定!");
}
else if(nownum==-1)
MessageBox("当前记录太靠前");
else
{
str2.Format("%ld",nownum);
str2+="是当前记录锁定记录";
MessageBox(str2);
}
}