?
Solved

Virtaul listview?

Posted on 1999-07-27
5
Medium Priority
?
931 Views
Last Modified: 2013-11-20
Dear All,

I know a control item which is called virtual listview is existed and I have read the article posted at the online library at microsoft.

My operating system is Window 98, the version of the following files

comctl32.dll is 4.72.3110.1
shell32.dll is 4.72.3110.6
shlwapi.dll is 4.72.3110.0

Also, I am using the professional edition of VC5.0 to develop my application.

How can I develop a virtual listview under this environment?
My project's view class is CFormView. I haev tried to add a listview at the resource editor but it doesn't contain the property LVS_OWNERDATA...Also, I cannot use the function SetItemCountEx(..).

Thanks!!!
0
Comment
Question by:hon67
[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
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
pau_serra earned 210 total points
ID: 1311709
What version of Visual C++ do you have?
If you have Visual C++ 6.0 SP2 CListCtrl::SetItemCountEx will work, if not, you must use the following:

ListCtrl.SendMessage(LVM_SETITEMCOUNT, (WPARAM) NumOfItems, (LPARAM)/*LVSICF_NOINVALIDATEALL*/0);

If you are coding a CListView derived view, all you have to do is the following:

In the CMyListView::PreCreateWindow:

BOOL CMyListView::PreCreateWindow(CREATESTRUCT& cs)
{
      cs.style&=~LVS_TYPEMASK;
      cs.style = cs.style | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDATA;

      return CListView::PreCreateWindow(cs);
}

in the CMyListView::OnInitialUpdate, set the extended styles and the number of items:

void CMyListView::OnInitialUpdate()
{
      MyDoc* pDoc = GetDocument();

      CListView::OnInitialUpdate();

      if (!pDoc)
            return;

      CListCtrl& ListCtrl=GetListCtrl();

// first of all, create the columns
      ListCtrl.InsertColumn( 0, "Column #1", LVCFMT_LEFT, 250, 0 );
      ListCtrl.InsertColumn( 1, "Column #2", LVCFMT_LEFT, 250, 1 );

// Here your extended styles:
      DWORD dwExStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES | LVS_EX_SUBITEMIMAGES | LVS_EX_INFOTIP;
      ListCtrl.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LPARAM(dwExStyle));      

// and now, the number of itmes:
      // ListCtrl.SetItemCountEx( 0, /*LVSICF_NOINVALIDATEALL*/0 );
      ListCtrl.SendMessage(LVM_SETITEMCOUNT, (WPARAM) pDoc->GetNumOfItems(), (LPARAM)/*LVSICF_NOINVALIDATEALL*/0);
}

And finally define the reflected message LVN_GETDISPINFO. You can do this with VC++ with class wizard, if u have a previous version, try this:
in .h add:

      afx_msg void OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult);

in the protected block.

in .cpp add:
      ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetdispinfo)
in the message map,
and
      void CMyListView::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
      {
            LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
            // TODO: Add your control notification handler code here
            
            *pResult = 0;
      }
in the bottom of file

CMyListView::OnGetdispinfo if called for every column of every item when it has to be painted. The code for this function may look like this:

void CMyListView::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
{
      LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;

      if ( pDispInfo->item.mask & LVIF_TEXT )
      {
            switch (pDispInfo->item.iSubItem)
            {
                  case 0:
                        _snprintf(pDispInfo->item.pszText, pDispInfo->item.cchTextMax, "Item %i", pDispInfo->item.iItem);
                        break;
                  default:
                        _snprintf(pDispInfo->item.pszText, pDispInfo->item.cchTextMax, "Item %i Col %i", pDispInfo->item.iItem, pDispInfo->item.iSubItem);
                        break;
            }
      }

      *pResult = 0;
}


that's all.

0
 

Author Comment

by:hon67
ID: 1311710
Dear pau_serra,

My project's view class is CFormView. How can I modify your code to implment the same thing?

At the function PreCrateWindow, I have tried to modify the following code from:

cs.style&=~LVS_TYPEMASK;
cs.style = cs.style | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDATA;

to
CListCtrl m_list1;
DWORD ListStyle = LVS_REPORT;
m_list1.ModifyStyle(ListStyle,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_OWNERDATA,0);

and put this in the OnInitialUpdate(..) Function.

Others are same, however, I get an debug assertion error.......

How can I modify your code?

Thanks!!!
0
 

Expert Comment

by:pau_serra
ID: 1311711
Ok hon67, here are the answer:

First of all, put a listctr in the dialog temaplate with ResourceEditor, and set onwer data in the 'more styles' tab.

(note from MS: Note Dynamically switching to and from the LVS_OWNERDATA style is not supported.)

Bind the resource with a CListCtrl using ClassWizard.

And all other is equal.

bye,

0
 

Author Comment

by:hon67
ID: 1311712
Hi pau_serra,

As I am using professional version of VC++5.0, there is no this option (LVS_OWNERDATA) at the more styles property page of the listview.

Is this mean that I cannot build a virtual listview in placing a listctrl from the resource editor?

Thanks!!!
0
 

Expert Comment

by:pau_serra
ID: 1311713
Try this:

In the .rc file, search for the list control,  may look like this:

    CONTROL         "List1",IDC_LISTCTRL,"SysListView32", WS_BORDER | WS_TABSTOP,20,20,200,65

and set LVS_OWNERDATA manually:

    CONTROL         "List1",IDC_LISTCTRL,"SysListView32", LVS_OWNERDATA | WS_BORDER | WS_TABSTOP,20,20,200,65

Bye!
0

Featured Post

Technology Partners: 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 …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

719 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