想实现大数据量下的CListCtrl的问题:
m_num = 50;//每次获取的buffer大小
利用函数PreSetBuffer(int StartRec,int RecCount)预先准备缓冲区,在用CListCtrl的OnGetdispinfoList函数填充值。基本实现了CListCtrl的显示问题,没有重载滚动条,所以拉动滚动条时还是比较缓慢。现在的问题是,在显示数据时时不时(极少情况)的蹦出错误,跟踪调试进去发现是itemid 的值>m_buffer.size();而且m_buffer.size()不对,竟然是3,而且是首次显示,RecCount=m_nnum的情况下,十分不解!不知道是哪里出错了?
void CKSQLView::PreSetBuffer(int StartRec,int RecCount)
{
m_start = StartRec;
m_end = m_start + RecCount;//区间[m_start,m_end)
if (m_end > m_count ) m_end = m_count;
m_buffer.erase(m_buffer.begin(),m_buffer.end());
for (int i=m_start;i< m_end;i++)//
{
vector<string> vcol;
TPI_Move(m_hSet,i+1);
for (int j=0;j<m_arrayFieldName.GetSize();j++)
{
CString text=_T("");
CString FieldName = m_arrayFieldName[j];
int nRet = GetFieldValue(theApp.m_hTPICon, m_hSet, FieldName, text) ;
vcol.push_back((LPTSTR)(LPCTSTR)text);
}
m_buffer.push_back(vcol);
}
}
void CKSQLView::OnGetdispinfoList(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM* pItem= &(pDispInfo)->item;
int itemid = pItem->iItem;
if (itemid >= m_end || itemid < m_start)
PreSetBuffer((itemid/m_nnum)*m_nnum,m_nnum);
itemid = itemid%m_nnum;
if (pItem->mask & LVIF_TEXT)
{
vector<string> vcol;
vcol = m_buffer.at(itemid);
string text;
if (pItem->iSubItem == 0)
{
TCHAR buffer[128];
_itot(pItem->iItem+1,buffer,10);
text = (LPTSTR)buffer;
}
else
text = vcol.at(pItem->iSubItem-1);
lstrcpyn(pItem->pszText, text.c_str(), pItem->cchTextMax);
}
*pResult = 0;
}