Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

problems populating combobox

Posted on 2002-07-29
2
Medium Priority
?
401 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 400 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

783 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