Solved

problems populating combobox

Posted on 2002-07-29
2
389 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Fox Pro commands 15 45
Run Program using VBScript 3 65
GUI: DIalog Stacking and Popping in MS C++ 4 74
Is AWS.RDS considered a part of "Big Data"? 4 108
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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