Share via


CListBox::GetSel

Retrieves the selection state of an item.

int GetSel( 
   int nIndex  
) const;

Parameters

  • nIndex
    Specifies the zero-based index of the item.

Return Value

A positive number if the specified item is selected; otherwise, it is 0. The return value is LB_ERR if an error occurs.

Remarks

This member function works with both single- and multiple-selection list boxes.

To retrieve the index of the currently-selected list box item, use CListBox::GetCurSel.

Example

// Dump all of the items select state.
   CString str;
   for (int i=0;i < m_myListBox.GetCount();i++)
   {
      str.Format(_T("item %d: select state is %s\r\n"),
         i,
         m_myListBox.GetSel( i ) > 0 ? _T("true") : _T("false"));
      AFXDUMP(str);
   }

Requirements

Header: afxwin.h

See Also

Reference

CListBox Class

Hierarchy Chart

LB_GETSEL

CListBox::SetSel

CListBox::GetCurSel