Partager via


CListBox::SetSel

Selects a string in a multiple-selection list box.

int SetSel(
   int nIndex,
   BOOL bSelect = TRUE 
);

Parameters

  • nIndex
    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.

  • 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.

Return Value

LB_ERR if an error occurs.

Remarks

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

To select an item from a single-selection list box, use CListBox::SetCurSel.

Example

// Select all of the items with an even index and
// deselect all others.
for (int i = 0; i < m_myODListBox.GetCount(); i++)
{
   m_myODListBox.SetSel(i, ((i%2) == 0));
}

Requirements

Header: afxwin.h

See Also

Reference

CListBox Class

Hierarchy Chart

CListBox::GetSel

LB_SETSEL

CListBox::SetCurSel

Other Resources

CListBox Members