Share via


CListBox::GetCurSel

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

int GetCurSel( ) const;

Return Value

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.

Remarks

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

Example

// 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);
}

Requirements

Header: afxwin.h

See Also

Reference

CListBox Class

Hierarchy Chart

LB_GETCURSEL

CListBox::SetCurSel

CListBox::GetSelItems

Other Resources

CListBox Members