Solved

problems populating combobox

Posted on 2002-07-29
2
388 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now