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. It is LB_ERR if no item is currently selected or if the list box is a multiple-selection list box.

GetCurSel should not be called for a multiple-selection list box.

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

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

Community Additions

ADD
Show:
© 2015 Microsoft