Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
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.


Retrieves the selection state of an item.

int GetSel(
   int nIndex 
) const;



Specifies the zero-based index of the item.

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

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

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

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

Community Additions

© 2015 Microsoft