Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 715
  • Last Modified:

Virtual List Contrl doesn't display Data

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
XWL
Asked:
XWL
  • 5
  • 5
1 Solution
 
AndyAinscowCommented:
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
 
XWLAuthor Commented:
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
 
AndyAinscowCommented:
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!

 
XWLAuthor Commented:
Good point! Here it is:

BEGIN_MESSAGE_MAP(CVirtualList, CListCtrl)
   ON_NOTIFY_REFLECT ( LVN_GETDISPINFO,  OnGetDispInfo )
END_MESSAGE_MAP()
0
 
AndyAinscowCommented:
That looks OK.
And there is no handler for the message in the dialog (or wherever you have the list control)?
0
 
XWLAuthor Commented:
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
 
XWLAuthor Commented:
I increased the point to 250.
0
 
AndyAinscowCommented:
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
 
AndyAinscowCommented:
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
 
XWLAuthor Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now