CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2004
    Posts
    293

    Question CComboBox question...

    Hi,

    I create CComboBox control dynamically in my program using the .Create() method, I fill the control with data, but when I run the program and click on the combo-box to expand its list - I can see only the first option and NO list is opened, how can I define the list length ?

    Thanks

  2. #2
    Join Date
    Jul 2003
    Posts
    147

    Re: CComboBox question...

    Just use SetItemHeight()

    MSDN Code:
    Code:
    // The pointer to my combo box.
    extern CComboBox* pmyComboBox;
    
    // Set the height of every item to be the
    // vertical size of the item's text extent.
    CString str;
    CSize   sz;
    int     dx=0;
    CDC*    pDC = pmyComboBox->GetDC();
    for (int i=0;i < pmyComboBox->GetCount();i++)
    {
       pmyComboBox->GetLBText( i, str );
       sz = pDC->GetTextExtent(str);
    
       pmyComboBox->SetItemHeight( i, sz.cy );
    }
    pmyComboBox->ReleaseDC(pDC);
    "Live only for tomorrow, and you will have a lot of empty yesterdays today."

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CComboBox question...

    I think you are looking for SetDroppedWidth() and SetHorizontalExtent().
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: CComboBox question...

    You can specify the height of the drop down list by using the CB_SETMINVISIBLE message or the ComboBox_SetMinVisible macro, however that is for Windows XP or later only.

    You can also change the height of the listbox by using SetWindowPos.
    Last edited by Marc G; November 9th, 2005 at 04:01 AM.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: CComboBox question...

    CB_SETMINVISIBLE is ok, but it requires Windows XP. For a more generic solution use the code bellow:

    Code:
            // assuming cbo is a CComboBox
    
            CRect rect;
    	cbo.GetWindowRect( rect);
    	rect.bottom += 100;
    	cbo.MoveWindow( rect);
    Basically, setting the Combo's height affects the height of the drop list.
    Har Har

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: CComboBox question...

    Quote Originally Posted by PadexArt
    CB_SETMINVISIBLE is ok, but it requires Windows XP. For a more generic solution use the code bellow:
    Exactly, that's why I edited my post immediately after posting it
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  7. #7
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: CComboBox question...

    Quote Originally Posted by Marc G
    Exactly, that's why I edited my post immediately after posting it
    I was adding my answer at the same time (11:01 - 11:02).
    Har Har

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