tags:

views:

488

answers:

2

I need to iterate through the items (strings) in a CComboBox to check which string is the longest. How can I get each item in the list?

+3  A: 

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;
   }
Adam Pierce
I kill you... and MSDN... Good answer but for the love of mike, a function call in the for test.. Ugh. int count = pmyComboBox->GetCount();
baash05
+2  A: 

See this link : http://weseetips.com/2008/10/05/how-to-adjust-the-drop-down-width-of-combobox/

Gook lock

lsalamon