CB_ADDSTRING for Combobox doesn't work as expected
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: CB_ADDSTRING for Combobox doesn't work as expected

  1. #1
    Join Date
    Aug 2002
    Location
    Hamburg / Germany
    Posts
    280

    Question [RESOLVED]CB_ADDSTRING for Combobox doesn't work as expected

    Heya Folks,
    need your help again. All I want is to initialize the strings for a ComboBox in a dialog created from a resource. Here's some code:
    Code:
    BOOL DialogProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam)
        {
          switch (message)
          {
            case WM_INITDIALOG :
            {
              HWND combo = GetDlgItem(hwnd,IDC_TYPECOMBO);
              const TCHAR* m_sArray[] = { _T( "Item1" ), _T( "Item2" ), _T( "Item3" ) };
              
              for (int i=0;i<3;i++)
              {
                LRESULT lt = SendMessage(combo,CB_ADDSTRING,0,(LPARAM)m_sArray[i]);
              }  
              SendMessage(combo, CB_SETCURSEL, 0, 0);
              return TRUE;
            }
        	case WM_COMMAND:
    	  switch(wParam)
    	  {
    	    case IDOK:
    	    case IDCANCEL:
                  iResult = wParam;
    	      EndDialog(hwnd,0);
                  return TRUE;
              }
          }
          return false;        
        }
    I expected to have 3 items in the combobox after that with the first one pre-selected. But all I get is one item, the first one. The other two are missing. Of cause I used the debugger and checked the return value of SendMessage. And as expected it was allways the itemindex of the freshly added item. So the items are in fact added. So why can't I see them?

    Thanks in advance for any help
    Sonny
    Last edited by AlionSolutions; February 25th, 2011 at 12:42 PM.

  2. #2
    Join Date
    Aug 2002
    Location
    Hamburg / Germany
    Posts
    280

    Re: CB_ADDSTRING for Combobox doesn't work as expected

    Well, I feel a bit stupid now...
    After changing
    SendMessage(combo, CB_SETCURSEL, 0, 0);
    to
    SendMessage(combo, CB_SETCURSEL, 1, 0);
    I noticed that the items in fact have been added. Just my Combo was to small to see them. So this has been solved by me, myself & I. Sorry for being stupid

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center