Reputation: 2064
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?
Upvotes: 4
Views: 5951
Reputation: 34365
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;
}
Upvotes: 7