Export (0) Print
Expand All

CListBox::GetCurSel

Retrieves the zero-based index of the currently selected item, if any, in a single-selection list box.

int GetCurSel( ) const;

The zero-based index of the currently selected item if it is a single-selection list box. It is LB_ERR if no item is currently selected.

In a multiple-selection list box, the index of the item that has the focus.

Do not call GetCurSel for a multiple-selection list box. Use CListBox::GetSelItems instead.


// Select the next item of the currently selected one.
int nIndex = m_myListBox.GetCurSel();
int nCount = m_myListBox.GetCount();
if ((nIndex != LB_ERR) && (nCount > 1))
{
   if (++nIndex < nCount)
      m_myListBox.SetCurSel(nIndex);
   else
      m_myListBox.SetCurSel(0);
}


Header: afxwin.h

Community Additions

ADD
Show:
© 2015 Microsoft