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

  • Take advantage of this on-demand webinar to learn how to deploy Windows apps to all workers, across all devices, with Citrix XenApp and XenDesktop. Additionally, our cloud expert will teach you to create a Windows 10-based VDI implementation and login using Citrix Receiver. Other key takeaways include how to: Deploy a multi–server Citrix XenApp/XenDesktop infrastructure Understand the core capabilities of Citrix on Azure, including virtualizing applications and desktops Register today!

  • Today, the ability to build applications that leverage emerging technologies including Internet of Things, cogitative, machine learning, and leveraging digital transformation separates the winners from the losers. However, using "cheaper" unsupported community software to build these applications has unforeseen cost disadvantages. IDC asked eight organizations using Red Hat JBoss Middleware solutions how their experiences with Red Hat compare with using community unsupported software. Read this analyst …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date