Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Selects a string in a multiple-selection list box.

int SetSel(
   int nIndex,
   BOOL bSelect = TRUE 



Contains the zero-based index of the string to be set. If –1, the selection is added to or removed from all strings, depending on the value of bSelect.


Specifies how to set the selection. If bSelect is TRUE, the string is selected and highlighted; if FALSE, the highlight is removed and the string is no longer selected. The specified string is selected and highlighted by default.

LB_ERR if an error occurs.

Use this member function only with multiple-selection list boxes.

// The pointer to my list box.
extern CListBox* pmyListBox;

// Select all of the items with an even index and
// deselect all others.
for (int i=0;i < pmyListBox->GetCount();i++)
   pmyListBox->SetSel(i, ((i%2) == 0));
© 2016 Microsoft