I'm developing a simple address book application which displays it's entries in a listview control. The entries are loaded from a file and stored in a array. My problem is I can't find a way to link the listview with the array (assign each item in the listview an ID so I can find it in the array). I've read about virtual listviews at MSDN but I find it too difficult for me to implement in my application. Isn't there any other way to do this ? (I don't need sample code, just some ideas). Thanks.

are you using MFC CListView class? or CListCtrl class? the InsertItem() method returns an integer that is the ID for that item. You can then call SetItemData() to connect the row number of your array to that item. Then when the user selects an item your program should call GetItemData() to retrieve the array row number.

are you using MFC CListView class? or CListCtrl class? the InsertItem() method returns an integer that is the ID for that item. You can then call SetItemData() to connect the row number of your array to that item. Then when the user selects an item your program should call GetItemData() to retrieve the array row number.

I'm using the Win32 API. The ListView_InsertItem macro returns me a zero-based index of the newly inserted item, but I don't think I can change that after insertion. The LVITEM structure I have to supply has a lParam member documented as an application-defined value in MSDN, but they also say it's only used by a few messages.

Use LVM_GETITEM or ListView_GetItem message to get that structure, but you probably already know that. I don't think you need to use virtual arrays if your array size does not change. The lParam member of the structure is set to the row number in your array.

This article has been dead for over six months. Start a new discussion instead.