CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 1999
    Posts
    9

    How to use combo box?

    I want to create a vanilla drop down list box. I've been trying to use the CComboBox, but to no avail.
    Whenever I run the program with it, it doesn't show the items, even if there are some. I'm using Visual C++ 6.0 w/ MFC. Any assistance would be appreciated.

    Thanks in advance.

    Eric Sebesta
    Bootprint Entertainment

  2. #2
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: How to use combo box?

    I think you need to select an item, otherwise it will be left unselected. m_CComboBox.SetCurSel(0) will select the first item in the box.


    -Safai

  3. #3
    Join Date
    Apr 1999
    Posts
    3,585

    Re: How to use combo box?

    Be sure to use CComboBox::AddString() to add your strings. This is usually done in the OnInitDialog() event if you're doing this for a dialog. Also, be sure to call UpdateData(FALSE) at the end of OnInitDialog().



    Gort...Klaatu, Barada Nikto!

  4. #4
    Join Date
    May 1999
    Posts
    9

    Re: How to use combo box?

    I tried both your and Mike's suggestions, but to no avail. Both suggestions did what they said they would: Mike's put the strings in the combo box, and your's did select the first string. But that's not my problem, even with both of those things implemented, when I click the drop-down button, it draws 2 or three lines of pixels below the combo box - not the "drop-down" effect we all know and love.

    Any other suggestions? (and thanks to both of you for your guesses)

    Eric Sebesta
    Bootprint Entertainment

  5. #5
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: How to use combo box?

    Now I know what your problem is. All you have to do is go to resource editor, click on your ComboBox control (the down arrow part). It should change between the 2 sizes, one for the 'regular' control size and the other is for the 'droped-down' control size. Adjust the 'droped-down' size to make the height bigger. That should solve your problem.

    -Safai

  6. #6
    Join Date
    May 1999
    Location
    JAPAN
    Posts
    11

    Re: How to use combo box?

    Hi,
    You need to set the Combobox style to 'drop-down-list'; You can do this either from the resource properties (styles tab) or in the code when you Create the combo using Create function (which takes styles as one of the parameter).

    giri

  7. #7
    Join Date
    May 1999
    Posts
    7

    Re: How to use combo box?

    I had exactly same problem. Everything worked fine, I was able to add strings to the box and later to select them by arrow keys, but never got list displayed.

    I solved it by deleting combo box in resource editor and using its member function Create() for creating box and setting its size and styles.

    I am guessing that when you create combo box in resource editor it has some default size which is about the size of the box, without dropping list. I could't find way to increase the size from resource editor.

    Damir


  8. #8
    Guest

    Re: How to use combo box?

    seems the problem is that the contents in the list are NOT displayed to you.
    in OnInitDialog(), code as following :
    CComboBox * c;
    c=(CComboBox * )GetDlgItem(IDC_COMBO);
    c->AddString(...);

    While in resource editor, make sure
    on the properties dialog, select the
    "styles" tab, and on the "owner draw"
    combo box, select "No".
    Compile and you will find the strings
    you added are displayed.

    Rong


  9. #9
    Join Date
    May 1999
    Posts
    5

    Re: How to use combo box?

    U can increase the size of the drop-down combo in the resource editor by exactly clicking on the down arrow(of the combo) and then resizing it.


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured