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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds