Solved

Virtual ListView!!!

Posted on 2000-05-04
4
418 Views
Last Modified: 2013-11-20
Hi,

As I am using VC++5.0 to develop my application, I need to display a lot of data (probably > 50000 items). Thus I choose to use Virtual Listview!!!

Now I face the following two problems!!!

1.) How get I get the text from the virtual listview?
     I found GetItemText() cannot return the text from the listview.

2.) How can I do the sorting the each column?

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
  • 2
4 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2779878
Hi,

>1.) How get I get the text from the virtual listview?
                          I found GetItemText() cannot return the text from the listview.

Just try one thing, After U calling the InsertItem(...) call SetItemText(...), I think this problem will be solved. If some paiting problems come, then just use Invalidate().

For sorting u have to write a compare function and sort. U will get lot of samples in the codeguru.developer.com listview section.

Try it out.

All the best
VinExpert
0
 
LVL 1

Accepted Solution

by:
ch_vasu earned 150 total points
ID: 2780054
There is a document in MSDN for Handling the Virtual Listviews.
Map this

1.

BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
   //{{AFX_MSG_MAP(CMyListCtrl)
   ON_NOTIFY(LVN_GETDISPINFO,IDC_LIST1, OnGetdispinfo)
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

Insert the items in OnInitialUpdate/OninitDialog

Then
Update the Values using this method
 
void CAboutDlg::OnGetdispinfoList(NMHDR* pNMHDR, LRESULT* pResult)
{
      LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
      
      LV_ITEM* pItem= &(pDispInfo)->item;
      
      int iItemIndx= pItem->iItem;
      
      if (pItem->mask & LVIF_TEXT) //valid text buffer?
      {
            switch(pItem->iSubItem)
            {
        case 0: //fill in main text
            lstrcpy(pItem->pszText,
                "Hello1");
            break;
        case 1: //fill in sub item 1 text
            lstrcpy(pItem->pszText,
                "Hello2");
            break;
        case 2: //fill in sub item 2 text
            lstrcpy(pItem->pszText,
                "Hello3");
            break;
            }
      }
      
      CString strTemp = m_cListCtrl.GetItemText(iItemIndx,0);
      AfxMessageBox(strTemp);

      *pResult = 0;
}

For geting the Text you can use function below.
      CString strTemp =
m_cListCtrl.GetItemText(iItemIndx,0);
2) Sorting
For sorting use this CallBack Function
// Sort the item in reverse alphabetical order.

static int CALLBACK
MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
   // lParamSort contains a pointer to the list view control.
   // The lParam of an item is just its index.
   CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
   CString    strItem1 = pListCtrl->GetItemText(lParam1, 0);
   CString    strItem2 = pListCtrl->GetItemText(lParam2, 0);

   return strcmp(strItem2, strItem1);
}

void snip_CListCtrl_SortItems()
{
   // The pointer to my list view control.
   extern CListCtrl* pmyListCtrl;

   // Sort the list view items using my callback procedure.
   pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
}





0
 

Author Comment

by:hon67
ID: 2781452
Hello ch_vasu,

Previously, I am not using Virtual Listview to display the data, I insert data and do the sorting of the listview like this:

--------------------------------------------------------
struct info
 {
     CString col1;
     CString clo2;
    CString col3;
};

 LV_ITEM lvi;
 lvi.mask = LVIF_TEXT | LVIF_PARAM;

 for(i = 0; i < nItems; i++)   // nItems = no of rows
{
      lvi.iItem = i;
      lvi.pszText = "Some thing";  //col 0 text
      struct info* pInfo = new struct info;
      pInfo->col0 = "Col1";
      pInfo->col1 = "Col2";
      pInfo->col2 = "Col3";

      lvi.lParam = (DWORD)pInfo;
      m_list1.InsertItem(lvi);
      m_lst1.SetItemText(nItems,1,"Col2");
      m_lst1.SetItemText(nItems,2,"Col3");
     
}

// sort the listview like this

pmyListCtrl->SortItems(MyCompareProc, (LPARAM) nColumnClicked);
------------------------------------------------------

Then I also do the sorting by using the callback function, but I do the comparsion by using the
structure pInfo instead of using the GetItemText function.

Now If I am using Virtual Listview, I found I don't need to use the InsertItem function and fill in the
LV_ITEM Structure.

I want to know whether I still can use this method to do the sorting.

Further, according to your suggested method?
What is the time need to sorting for about 50000 rows with 10 cols? I afraid the time use to call the function GetItemText is very time consuming?                  

0
 
LVL 1

Expert Comment

by:ch_vasu
ID: 2788091

You will get more information about how to RetrieveItem from Virtual list control in MSDN help.
1. To get the Help type 'List View Updates in Internet Explorer' in the MSDN index. There click on heperlink 'Virtual List View'. You can change use that sample code to continue.  

Note :- The section "Compatibility issues: styles, states, and messages" in MSDN says --

List View Control Styles: All four of the list view styles (icon, small icon, list, and report view) support the LVS_OWNERDATA style. However, this style will not work with the LVS_SORTASCENDING or LVS_SORTDESCENDING style.

I believe by using Cache Management you can reduce the sort time.

Try this
All the Best.
-Vasudev

0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

VM backup deduplication is a method of reducing the amount of storage space needed to save VM backups. In most organizations, VMs contain many duplicate copies of data, such as VMs deployed from the same template, VMs with the same OS, or VMs that h…
Microsoft will be releasing the Windows 10 Creators Update in just a matter of weeks. Are you prepared? Follow these steps to ensure everything goes smoothly and you don't lose valuable data on your PC.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

729 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