nke2000
asked on
problems populating combobox
I give up!! I'm having problems populating a combobox with the numbers 1 - 10. Anybody see anything wrong with this code. It's from OnInitDialog. The combobox is on a dialog created using the ATL wizard. First call to SendMessage returns 0. GetLastError() returns 0. Second call to SendMessage return -1, which is right because the combobox was not properly populated.
const ULONG MAX_POSSIBLE_MIGS = 10;
HWND h_Combo = GetDlgItem(IDC_MAXMIGS_COM BO);
//populate the combo box control
for( int x = 1; x <= MAX_POSSIBLE_MIGS; ++x )
{
COMBOBOXEXITEM item = {0};
item.mask = CBEIF_TEXT;
item.iItem = - 1;
TCHAR buff[10] = {0};
_itow( x, buff, 10 );
item.pszText = buff;
// item.cchTextMax = (lstrlen(buff)+1);
long ret = SendMessage( h_Combo, CBEM_INSERTITEM, NULL, reinterpret_cast<LPARAM>(& item));
long err = GetLastError();
m_vComboItems.push_back(&i tem);
}
///set the default concurrent migrations to 3
HWND h = GetDlgItem(IDC_MAXMIGS_COM BO);
long ret = SendMessage(h, CB_SETCURSEL, static_cast<WPARAM>(4), NULL );
return FALSE; // Let the system set the focus
const ULONG MAX_POSSIBLE_MIGS = 10;
HWND h_Combo = GetDlgItem(IDC_MAXMIGS_COM
//populate the combo box control
for( int x = 1; x <= MAX_POSSIBLE_MIGS; ++x )
{
COMBOBOXEXITEM item = {0};
item.mask = CBEIF_TEXT;
item.iItem = - 1;
TCHAR buff[10] = {0};
_itow( x, buff, 10 );
item.pszText = buff;
// item.cchTextMax = (lstrlen(buff)+1);
long ret = SendMessage( h_Combo, CBEM_INSERTITEM, NULL, reinterpret_cast<LPARAM>(&
long err = GetLastError();
m_vComboItems.push_back(&i
}
///set the default concurrent migrations to 3
HWND h = GetDlgItem(IDC_MAXMIGS_COM
long ret = SendMessage(h, CB_SETCURSEL, static_cast<WPARAM>(4), NULL );
return FALSE; // Let the system set the focus
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I used CB_ADDSTRING and everything worked fine. Thanks for your willingness to help.
--NKE
p.s. I tried item.iItem = (x-1) and it didn't work...tried that before I posted the question.