Chris
Chris

Reputation: 179

Iterating over ListView Items win32 api

I currently have a handle to my Listview via HWND lv = GetDlgItem(hDlg, MY_LISTVIEW)

and its currently populated with items using ListView_SetItemText(); I want to update each item in that listview based on data that has been updated externally. How would I iterate over each listview item given my handle?

Upvotes: 0

Views: 953

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37132

ListViews use a 0-based index to identify items, so to iterate over the items it's simply a matter of getting the total and then running a loop that counts from 0. For example,

int iNumItems = ListView_GetItemCount(lv);
for (int iIndex = 0; iIndex < iNumItems; ++iIndex)
{
    // update this item
    ListView_SetItemText(lv, iIndex, 0, ...);
}

Upvotes: 4

Related Questions