我在停靠栏上放了listcontrol控件,代码如下:要实现当停靠栏显示时,listcontrol中的数据也显示出来!extern _ConnectionPtr pConn; BOOL CAcDialogBar::Create (CFrameWnd *pParent, UINT nIDTemplate, UINT style, UINT nID) { if ( !CDialogBar::Create (pParent, nIDTemplate, style, nID) ) return (FALSE) ; mSizeCurrent =m_sizeDefault ; CAcDialogBar m_MyBar; m_ctrlCoPeople.SubclassDlgItem(IDC_LS_COPeople,this); DWORD dwStyle = m_ctrlCoPeople.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT dwStyle |= LVS_EX_GRIDLINES; m_ctrlCoPeople.SetExtendedStyle(dwStyle); //设置扩展风格 m_ctrlCoPeople.InsertColumn(0,"协同用户"); m_ctrlCoPeople.InsertColumn(1,"协同方式"); m_ctrlCoPeople.InsertColumn(2,"用户IP"); m_ctrlCoPeople.InsertColumn(3,"协同项目"); m_ctrlCoPeople.InsertColumn(4,"协同模块"); m_ctrlCoPeople.SetColumnWidth(0,100);//设置列的宽度。 m_ctrlCoPeople.SetColumnWidth(1,100); m_ctrlCoPeople.SetColumnWidth(2,100); m_ctrlCoPeople.SetColumnWidth(3,100); m_ctrlCoPeople.SetColumnWidth(4,100); CString vsql,vstrType,vstrName,vstrIp,vstrPid,vstrMid; _RecordsetPtr vst; _variant_t Holder; int i = 0; vst.CreateInstance(__uuidof(Recordset)); vsql.Format("SELECT * FROM tempcoinfo"); vst->Open(_variant_t(vsql),pConn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText); if(!vst->adoEOF) { m_ctrlCoPeople.DeleteAllItems(); vst->MoveFirst(); while (!vst->adoEOF) { LV_ITEM lvitem; lvitem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvitem.state = 0; lvitem.stateMask = 0; //char temp[50]; lvitem.iItem = i; lvitem.iSubItem = 0; //lvitem.pszText =itoa(i, temp, 10); //m_ctrlCoPeople.InsertItem(&lvitem); Holder=vst->GetCollect("tempType"); vstrType = Holder.vt==VT_NULL?""char *)(_bstr_t)Holder; Holder=vst->GetCollect("tempname"); vstrName= Holder.vt==VT_NULL?""char *)(_bstr_t)Holder; Holder=vst->GetCollect("tempip"); vstrIp= Holder.vt==VT_NULL?""char *)(_bstr_t)Holder; Holder=vst->GetCollect("coprojectid"); vstrPid= Holder.vt==VT_NULL?""char *)(_bstr_t)Holder; Holder=vst->GetCollect("comodeid"); vstrMid= Holder.vt==VT_NULL?""char *)(_bstr_t)Holder; lvitem.pszText =(LPSTR)LPCSTR(vstrName) ; m_ctrlCoPeople.InsertItem(&lvitem); m_ctrlCoPeople.SetItemText(i,1,(LPCTSTR)vstrType); m_ctrlCoPeople.SetItemText(i,2,(LPCTSTR)vstrIp); m_ctrlCoPeople.SetItemText(i,3,(LPCTSTR)vstrPid); m_ctrlCoPeople.SetItemText(i,4,(LPCTSTR)vstrMid); vst->MoveNext(); i=i+1; } } vst->Close(); delete vst; return (TRUE) ; } 可是当运行时,所有m_ctrlCoPeople.SetItemText()语句只能在最后一条记录显示出数据来,其余的都不显示查询到的数据,请问该问题怎么解决,谢谢!!! |