Iterating through MFC CComboBox items

I need to iterate over items (lines) in CComboBox to check which line is the longest. How can I get each item in the list?

+1


source to share


1 answer


Try the GetLBTextLen () function

Here's an example from MSDN :



// Dump all of the items in the combo box.
   CString str, str2;
   int n;
   for (int i=0;i < pmyComboBox->GetCount();i++)
   {
      n = pmyComboBox->GetLBTextLen( i );
      pmyComboBox->GetLBText( i, str.GetBuffer(n) );
      str.ReleaseBuffer();

      str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
      afxDump << str2;
   }

      

+4


source







All Articles