Solved

problems populating combobox

Posted on 2002-07-29
2
390 Views
Last Modified: 2013-12-03
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_COMBO);
     //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(&item);
     }
     ///set the default concurrent migrations to 3
     HWND h = GetDlgItem(IDC_MAXMIGS_COMBO);
    long ret =     SendMessage(h, CB_SETCURSEL,  static_cast<WPARAM>(4), NULL  );
     return FALSE;  // Let the system set the focus
0
Comment
Question by:nke2000
2 Comments
 
LVL 4

Accepted Solution

by:
mblat earned 100 total points
ID: 7185833
Try:

item.iItem = x - 1;

instead of
item.iItem = - 1;

also ( not related to question )
         
m_vComboItems.push_back(&item);  doesn't look good.

item is local variable and you are storing pointer to it.  So how are you planing to use it, once you left your loop it doesn't point to anything. ?????
       
0
 

Author Comment

by:nke2000
ID: 7186100
mblat,
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.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question