?
Solved

Virtual List Contrl doesn't display Data

Posted on 2005-02-28
10
Medium Priority
?
676 Views
Last Modified: 2013-11-20
Hi there,

I am working on a MFC CListCtrol derived class CVirtualList control. I set its style to LVS_OWNERDATA. According to my understanding, as long as the list control is set to owner data, the LVN_GETDISPINFO message will be sent if CListCtrl’s function SetItemCount(int) is called. However, My virtual list control‘s LVN_GETDISPINFO handler never be called when the CListCtrl::SetItemCount(int) is called. It is strange to me. Could anyone here tell me if there is something I missed?
Environment: Win2K/SP4/VC6.0.

Thank you very much,

XWL
0
Comment
Question by:XWL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 13427077
Are you supplying the data from the list control or from the owner window?
Have you put a breakpoint in the handler to check it isn't being called - maybe it is but something else is the problem
0
 

Author Comment

by:XWL
ID: 13428166
Yes, I do supply the data from the owner window. Also I put a breakpoint in the message handler. This is the way to figure out that the handler is never called.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 13428401
Please post some code for the  LVN_GETDISPINFO message - MessageMap entry
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:XWL
ID: 13429774
Good point! Here it is:

BEGIN_MESSAGE_MAP(CVirtualList, CListCtrl)
   ON_NOTIFY_REFLECT ( LVN_GETDISPINFO,  OnGetDispInfo )
END_MESSAGE_MAP()
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 13430480
That looks OK.
And there is no handler for the message in the dialog (or wherever you have the list control)?
0
 

Author Comment

by:XWL
ID: 13439775
one thing I should mention is that I am using my virtual list control in a CView derived class. in function InitUpdate, I casted the standard CListCtrl to my virtual List control:

// Class declaretions
class CMyListView: public CView
{
......
protected:
   CListCtrl m_ctlList;
};
class CVirtualListView: public CMyListView
{
......
protected:
   CVirtualListCtrl   m_pctlVirtualList;
};

class CVirtualListCtrl : public CListCtrl
{
......
};

// Class implemetation
CVirtualListView::OnInitialUpdate()
{
   CMyListView::OnInitialUpdate();

   // Cast "standard" CListCtrl object to CVirtualListCtrl object
   if (IsWindow(m_ctlList.m_hWnd))
   {
      m_pctlVirtualList = (GCVirtualListCtrl*)&m_ctlList;
      ASSERT (m_pctlVirtualList->m_hWnd == m_ctlList.m_hWnd);
      m_pctlVirtualList->ModifyStyle( 0, LVS_REPORT | LVS_OWNERDATA );
}

The problem is that the m_pctlVirtualList works partially and its LVN_GETDISPINFO  handler is never been called in the CVirtualListView class. The class CVirtualListCtrl works well in other windows such as in a CDialog-derived classes.

Please help me. Thank you,

XWL
0
 

Author Comment

by:XWL
ID: 13439778
I increased the point to 250.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 13440029
OK.  You have modified the style of the list control linked to the view.  BUT it is still a CListCtrl, not a window based on your CVirtualListCtrl.
You could trap the LVN_GETDISPINFO message in your view and return the info required from that.
Alternatively it might be simpler to have a standard CView based view and create your virtual list control dynamically (eg. in OnInitialUpdate of the view) and make the list control fill the view (OnSize of the view).
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 1000 total points
ID: 13440093
ps. Read up subclassing in help.  That is how you 'change' the class an existing window is based on.  (If you single step into the DDX_Control you will see some subclassing there - dialog based app).  
m_pctlVirtualList = (GCVirtualListCtrl*)&m_ctlList; is an example of casting, it just affects the m_pctlVirtualList NOT the original m_ctlList.
0
 

Author Comment

by:XWL
ID: 13443633
There are two points that cause the problem were found as AndyAinscow pointed out:
1) The message map entry should follow derivation relationship of the classes, otherwise the message handler would be called;
2)  In my case, m_pctlVirtualList = (GCVirtualListCtrl*)&m_ctlList simply doesn't work. After the casting, m_ctlList still exists and message won't be sent to the casted one. My solution is to destory m_ctlList in CVirtualListView::OnCreate( LPCREATESTRUCT lpcs )function, and then create a CVirtualListCtrl object. After this, the CVirtualListVieew works well.

Thank you all for great ideas, well done!

XWL
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question