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
2008-12-19 12:00:48
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
2009-01-06 01:51:46
+2
A:
See this link : http://weseetips.com/2008/10/05/how-to-adjust-the-drop-down-width-of-combobox/
Gook lock
lsalamon
2008-12-19 12:08:10