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:



Comments

  • how about SetSelectionMark

    Posted by leolyy on 01/10/2006 09:25pm

    how about SetSelectionMark 3x

    Reply
  • can not see old comments

    Posted by cxq2003 on 12/03/2005 08:24pm

    can not see old comments

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds