This depends on the type of selection (single or multiple rows).
To get the numbers of selected rows use
CListCtrl::GetSelectedCount() [
^]. If the count is not zero call
prevItemIndex = GetNextItem(prevItemIndex, LVNI_SELECTED);
count times (or until -1 is returned) where
prevItemIndex
is -1 initially.
Alternatively use
GetFirstSelectedItemPosition()
and
GetFirstSelectedItemPosition()
.
If your report list is not set to full row selection, you have to check each column of the selected rows using
GetItem()
and checking there for the selection state:
LVITEM item;
item.iItem = prevItemIndex;
item.mask = LVIF_STATE;
item.stateMask = LVIS_SELECTED;
GetItem(&item);
if (item.state & LVIS_SELECTED)
{
}
Pass the returned index(es) to
GetItemText()
to retrieve the text.
If you want to react when the selection is changed (e.g. to update the status bar), handle the
LVN_ITEMCHANGED notification code (Windows)[
^]:
ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnLvnItemChanged)
void CMyListView::OnLvnItemChanged(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
if ((pNMLV->uChanged & LVIF_STATE) && ((pNMLV->uOldState ^ pNMLV->uNewState) & LVIS_SELECTED))
{
}
*pResult = 0;
}