How to set an item in CListCtrl as selected?

DarshanG picture DarshanG · Nov 13, 2009 · Viewed 35.4k times · Source

ClistCtrl is set to single selection & single column in report view with no header.

I have tried SetItemState(0,LVIS_SELECTED,LVIF_STATE) and
SetSelectionMark(int index) but these don't work.

Answer

EdM picture EdM · Dec 30, 2010

you also need to call SetSelectionMark after updating the item states.

SetItemState(prev_item, ~LVIS_SELECTED, LVIS_SELECTED);
SetItemState(new_selected_item, LVIS_SELECTED, LVIS_SELECTED);
SetSelectionMark(new_selected_item);