初学MFC, 准备使用CListCtrl来显示表格数据, 但是运行程序的时候总是出现DEBUG 断言失败错误的对话框, 忽略所有的错误后, 表格控件最后也没有显示数据.
这里是显示表格最简单的代码:
//插入列名
m_listReport.InsertColumn( 0, "COL1", LVCFMT_LEFT, 40 );
m_listReport.InsertColumn( 1, "COL2", LVCFMT_LEFT, 50 );
//插入数据
int rowId = m_listReport.InsertItem(0,"4444");
m_listReport.SetItemText(rowId, 0, "5555");
m_listReport.SetItemText(rowId, 1, "6666");
程序运行到m_listReport.SetItemText(rowId, 0, "5555"); 的时候就会出现断言失败的错.
通过DEBUG方法SetItemText, 发现代码里 (GetStyle() & LVS_OWNERDATA)==0为假, 所以程序运行到这里就会报错.
winctrl2.cpp中Line:494为
BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT((GetStyle() & LVS_OWNERDATA)==0);//Line 494
LVITEM lvi;
lvi.iSubItem = nSubItem;
lvi.pszText = (LPTSTR) lpszText;
return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXT, nItem, (LPARAM)&lvi);
}
于是就在资源文件里把list control的OWNERDATA属性设置为false, 程序就运行正常了,也可以显示数据了.
那什么是OWNERDATA属性了,它是做什么用的呢, 于是在MSDN里查了下发现以下内容, 这个属性用来处理大数据的显示的, 至于使用它, 就没有继续深究下去,现在这里mark下,以后需要用到的时候再看看.
Virtual
List-View Style
A virtual list view is a list-view control that has the LVS_OWNERDATA style. This style enables the control to handle millions of items because the owner receives the burden of managing item data. This allows you to use the virtual list-view control with large
databases of information, where specific methods of data access are already in place.
A virtual list-view control maintains very little item information itself. Except for the item selection and focus information, the owner of the control must manage all item information. Other processes request item information from the owner by using LVN_GETDISPINFO
notification codes.
Because this type of list control is intended for large data sets, it is recommended that you cache requested item data to improve retrieval performance. The list view provides a cache-hinting mechanism to assist in optimizing the cache. The hint is implemented
in the form of an LVN_ODCACHEHINT notification code.
457




被折叠的 条评论
为什么被折叠?



