CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2005
    Posts
    3

    Question Extend width of Drop-down list of Combo Box

    The diablog window size is fixed, and the width of the Combo Box is fixed as well. But some of the drop-down list items contain long strings. How can I just widen the drop-down part of the combo box but keep the fixed size of the combo box?

    Thanks!!!

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Extend width of Drop-down list of Combo Box

    CB_SETHORIZONTALEXTENT:

    Quote Originally Posted by MSDN
    An application sends the CB_SETHORIZONTALEXTENT message to set the width, in pixels, by which a list box can be scrolled horizontally (the scrollable width). If the width of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden or, if the combo box has the CBS_DISABLENOSCROLL style, disabled.
    This should do your work.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: Extend width of Drop-down list of Combo Box

    You could also try following:

    Code:
    ::SendMessage(yourComboBoxHandle, CB_SETDROPPEDWIDTH, nWidth, 0);
    Hope this helps

    Hob

    EDIT: Removed MFC specific code
    Last edited by Hobson; August 31st, 2005 at 07:02 AM.
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Extend width of Drop-down list of Combo Box

    I don't like MFC stuff here, anyway your code will only result in a brighter dropdown-listbox of the combobox. Which isn't very smooth. It's better to have a scrollbar and don't let the listbox bloat up too much.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: Extend width of Drop-down list of Combo Box

    If its better to have a scrollbar or wide list, depends on users. I do not like scrolling too much when some listbox has items with common prefix and invisible last part. Anyway, OP asked for widening a listbox, so this is what I gave him.

    And about MFC stuff: In this case MFC just wraps Win32 API call (SendMessage). Theres nothing MFC specific here. I just wanted to say that if someone is interested in how to do something with Win32API, then he / she just should peek into MFC sources. This is often very helpful.

    But of course dropdown list should not be too wide. This would be very irritating.

    Hob
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  6. #6
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Extend width of Drop-down list of Combo Box

    Quote Originally Posted by Hobson
    And about MFC stuff: In this case MFC just wraps Win32 API call (SendMessage). Theres nothing MFC specific here. I just wanted to say that if someone is interested in how to do something with Win32API, then he / she just should peek into MFC sources. This is often very helpful.
    But the OP didn't asked how MFC does it. And posting inside MFC code can be very dangerous for people who haven't used MFC, OOP with WinAPI that much. It can be very irritating. So posting just a simple non-MFC code piece showing how to use this message might be more helpfull than all this inside MFC stuff. Or just providing the MSDN Platform SDK reference to the message/function; as I do.

    Quote Originally Posted by Hobson
    But of course dropdown list should not be too wide. This would be very irritating.
    Personal preference as you said. But imagine a user who just uses 800x600 as a screen resolution. A widend combobox listbox might eat his half screen.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  7. #7
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: Extend width of Drop-down list of Combo Box

    Agree to both of above.

    I removed MFC (potentially misleading and irritating) part of my 1st post



    Hob
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  8. #8
    Join Date
    Aug 2005
    Posts
    3

    Re: Extend width of Drop-down list of Combo Box

    CB_SETHORIZONTALEXTENT works like a charm!! THANKS, GUYS!!

    We don't use MFC at work, just good old Win32 API. But I'd like to look into MFC later.

  9. #9
    Join Date
    Aug 2005
    Posts
    3

    Re: Extend width of Drop-down list of Combo Box

    OOPS.. I mean CB_SETDROPPEDWIDTH

  10. #10
    Join Date
    Nov 2021
    Posts
    1

    Re: Extend width of Drop-down list of Combo Box

    Thank you Hobson.

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,109

    Re: Extend width of Drop-down list of Combo Box

    Victor Nijegorodov

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