Problem with Virtual List View
-
Dear all, I am writting a database application for Pocket PC 2002 using the eVC++ 3.0 Now, I have a problem that need to add a lot of items on the CListCtrl. I had tried following the article found on PocketPCDN about Virtual List View http://www.pocketpcdn.com/articles/list\_view.html but my program always displays an error message: "Assertion Failed Test: File winctrl2.cpp, Line 504" Here is my code to create the CListCtrl if(m_wndList.Create (WS_CHILD | WS_VISIBLE | LVS_OWNERDATA | LVS_SINGLESEL | LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER, CRect(0,0,243,224), this, MAIN_LIST)) { // Set List Control style to Full Row Select DWORD dwStyle = m_wndList.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT; m_wndList.SetExtendedStyle(dwStyle); } Any help is very appriciated. Regards, -BHKien
-
Dear all, I am writting a database application for Pocket PC 2002 using the eVC++ 3.0 Now, I have a problem that need to add a lot of items on the CListCtrl. I had tried following the article found on PocketPCDN about Virtual List View http://www.pocketpcdn.com/articles/list\_view.html but my program always displays an error message: "Assertion Failed Test: File winctrl2.cpp, Line 504" Here is my code to create the CListCtrl if(m_wndList.Create (WS_CHILD | WS_VISIBLE | LVS_OWNERDATA | LVS_SINGLESEL | LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER, CRect(0,0,243,224), this, MAIN_LIST)) { // Set List Control style to Full Row Select DWORD dwStyle = m_wndList.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT; m_wndList.SetExtendedStyle(dwStyle); } Any help is very appriciated. Regards, -BHKien
It look like you have tried to call the SetItemText function of the CListCtrl class with the LVS_OWNERDATA style flag and if you take a look in the source code of winctrl2.cpp, Line 504 you will see an assert:
BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT((GetStyle() & LVS_OWNERDATA)==0);
LVITEM lvi;
lvi.iSubItem = nSubItem;
lvi.pszText = (LPTSTR) lpszText;
return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXT, nItem, (LPARAM)&lvi);
}So, this function call is not allowed with the LVS_OWNERDATA style flag! Regards, Daniel. -- FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. ;)
-
It look like you have tried to call the SetItemText function of the CListCtrl class with the LVS_OWNERDATA style flag and if you take a look in the source code of winctrl2.cpp, Line 504 you will see an assert:
BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT((GetStyle() & LVS_OWNERDATA)==0);
LVITEM lvi;
lvi.iSubItem = nSubItem;
lvi.pszText = (LPTSTR) lpszText;
return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXT, nItem, (LPARAM)&lvi);
}So, this function call is not allowed with the LVS_OWNERDATA style flag! Regards, Daniel. -- FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. ;)
Daniel is right. Furthermore, to use the
LVS_OWNERDATA
style, you have to handle a number of notification messages, most notably:LVN_GETDISPINFO
: Sent by the list control when it needs to render item data.LVN_ODCACHEHINT
: If you have a cache with data, use this callback to prepare it. This message is received beforeLVN_GETDISPINFO
, so you can prepare the cache with the requested data.LVN_ODFINDITEM
: Used to find an item on the cache.LVN_ODSTATECHANGED
: Cached items have changed their state. Regards, João Paulo Figueira Embedded MVP -
Daniel is right. Furthermore, to use the
LVS_OWNERDATA
style, you have to handle a number of notification messages, most notably:LVN_GETDISPINFO
: Sent by the list control when it needs to render item data.LVN_ODCACHEHINT
: If you have a cache with data, use this callback to prepare it. This message is received beforeLVN_GETDISPINFO
, so you can prepare the cache with the requested data.LVN_ODFINDITEM
: Used to find an item on the cache.LVN_ODSTATECHANGED
: Cached items have changed their state. Regards, João Paulo Figueira Embedded MVPThank you all, I have one more thing to ask: I am writting a derived class from CListCtrl. Is there any way to access the item data of the base class if my class use the LVS_OWNERDATA mode? Thanks for your help! -BHKien
-
Thank you all, I have one more thing to ask: I am writting a derived class from CListCtrl. Is there any way to access the item data of the base class if my class use the LVS_OWNERDATA mode? Thanks for your help! -BHKien
Remember: if you are deriving (public inheritance) from a
CListCtrl
it means that your class is aCListCtrl
. So, everything is accessible. Regards, João Paulo Figueira Embedded MVP -
Remember: if you are deriving (public inheritance) from a
CListCtrl
it means that your class is aCListCtrl
. So, everything is accessible. Regards, João Paulo Figueira Embedded MVPThanks. -BHKien