Select item programmatically


Unlike a listbox control, the list view control does not
has a SetCurSel() or the SetSel() function. To achieve that, we can use
the following statement.

m_listctrl.SetItemState( rownum,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);

If you dont use the LVIS_FOCUSED flag and the control allows muliple selection,
then you will likely end up with two items highlighted – one that has the
focus and one that you just selected.

Another gotcha is that if you do not set the LVS_SHOWSELALWAYS style
for the ListView control, you dont see the highlighting till the control
gets focus.

 

Comments:

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read