Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problems populating combobox

Posted on 2002-07-29
2
Medium Priority
?
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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 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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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