nField//用于排序的索引号
void CNewListView::DispAllRec(int nTable,int nField)
{
   CRecordset *cSet;
   if(nTable==1) cSet=new CStudentSet();
   if(nTable==2) cSet=new CScoreSet();
   if(nTable==3) cSet=new CCourseSet();
   else return;
   CListCtrl &m_listctrl=GetListCtrl();
   m_listctrl.DeleteAllItems();
   int nColumnCount=m_listctrl.GetHeaderCtrl()->GetItemCount();
   for(int j=0;j<nColumnCount;j++)
   m_listctrl.DeleteColumn(0);
   cSet->Open();
   CODBCFieldInfo field;
   int nWidth;
   CString strField,strName;
   for(UINT i=0;i<cSet->m_nFields;i++)
   {
   cSet->GetODBCFieldInfo(i,field);
        strName=field.m_strName;
nWidth=field.m_nPrecision*9;
if(nWidth<strName.GetLength()*9)nWidth=strName.GetLength()*9;
if(nWidth<40) nWidth=40;
m_listctrl.InsertColumn(i,strName,LVCFMT_LEFT,nWidth);
if(i==(UINT)nField)strField=field.m_strName;   }
   cSet->Close();
   if(!strField.IsEmpty())cSet->m_strSort=strField;
   cSet->Open();
   int nItem=0;
   CString str;
   while(!cSet->IsEOF())
   {
   for(UINT i=0;i<cSet->m_nFields;i++)
   {
   cSet->GetFieldValue(i,str);
   if(i==0) m_listctrl.InsertItem(nItem,str);
   else
   m_listctrl.SetItemText(nItem,i,str);
   }
   nItem++;
   cSet->MoveNext();   }
   cSet->Close();
   if(cSet)delete cSet;
}void CNewListView::OnStudentinf() //菜单响应函数,
{
// TODO: Add your command handler code here
DispAllRec(1,2);
}
为什么在列表视图里没显示表中的信息,

解决方案 »

  1.   


    if(nTable==1) cSet=new CStudentSet(); 
    else if(nTable==2) cSet=new CScoreSet(); 
    else if(nTable==3) cSet=new CCourseSet(); 
    else return; 
      

  2.   

        if(nTable==1) cSet=new CStudentSet(); 
        else if(nTable==2) cSet=new CScoreSet(); 
        else if(nTable==3) cSet=new CCourseSet(); 
        else return; 
      

  3.   

    你的程序有问题:
      CRecordset *cSet; 
      if(nTable==1) cSet=new CStudentSet(); 
      if(nTable==2) cSet=new CScoreSet(); 
      if(nTable==3) cSet=new CCourseSet(); 
      else return; 
    如果nTable==1或nTable==2的话,在分配内存后,接下来就要执行: else return;这一句,
    所以,你的程序已经退出去了,就谈不上显示数据的问题了。
      

  4.   

    对,是这样。
    其实楼主调试一下就能发现这个问题了。
    改一下:
    CRecordset *cSet; 
      if(nTable==1) cSet=new CStudentSet(); 
      else if(nTable==2) cSet=new CScoreSet(); 
      else if(nTable==3) cSet=new CCourseSet(); 
      else return;