Select item programmatically
Posted
by Zafir Anjum
on August 6th, 1998
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:
- This is article is for setting the selection but Please Tell me How do we get a selected item index - Muhammad Amir Rao (2003/07/25)
- Select item programitically - Anand V. Reddy (2003/07/17)
- Row selection/deselection without SHIFT key (good for touch screen app) - Sergey T (2003/06/03)
- Thank you - James (2003/02/15)
- A Thousand Thank Yous - Robert (2003/02/11)
- how to handle LVN_ENDLABELEDIT? - XYZ (2003/02/05)
- select multiple Item without pressing CTRL/SHIFT key? - Rupnarayan Sarkar (2002/08/10)
- SetSelectionMark() - hultee (2002/06/16)
- THANK YOU! - Blake (2002/05/23)
- This does not call NM_CLICK handler - tahir (2001/07/27)
- To scroll the selected item to the top - Balint Akos (2000/08/08)
- How to scroll the list - Olivier Fresse (1999/02/22)
- Doesn't scroll the item into view - Peter Papanikolaou (1999/02/01)
- Setting the state of a list control item programatically - Multiple Items Recieving Focus - Nathan Lovell (1998/09/30)

Comments
how about SetSelectionMark
Posted by leolyy on 01/10/2006 09:25pmhow about SetSelectionMark 3x
Replycan not see old comments
Posted by cxq2003 on 12/03/2005 08:24pmcan not see old comments
Reply