Click here to Skip to main content
Licence 
First Posted 3 Apr 2000
Views 167,409
Bookmarked 37 times

CComboBox with disabled items

By | 14 Apr 2000 | Article
combobox with disabled items
  • Download source files - 3 Kb

    Introduction

    This class extends the usual combo box by the possibility of disabling some items. Those items are listed in the combo box but they can't be selected by the user.

    The basic derivation has four parts:

    1. By making the combo box owner-draw, we can draw the disabled items in a distinct color.
    2. Overriding the WM_LBUTTONUP handler of the enclosed list box, we can actually disable clicking on the disabled items.
    3. Overriding CharToItem handler, we can disable picking the disabled items by keyboard.
    4. And finally, by reacting to reflected CBN_SELENDOK, we can assure that a disabled item was not, by bug in CExtendedComboBox implementation, selected.

    The reader is urged to carefully study the code to understand the internals of the CExtendedComboBox class.

    The use of WM_CTLCOLORLISTBOX message for subclassing comes from another article.


    How to use the class

    The CExtendedComboBox class is a drop-in replacement of CComboBox. You simply #include "ExtendedComboBox.h" and instead of CComboBox class you use CExtendedComboBox class in your CDialog-derived class.

    The behaviour of CExtendedComboBox is customizable by overriding:

    virtual BOOL IsItemEnabled(UINT) const;
    

    This function takes index of item as an argument (the function must explicitely check that the argument is not, in fact, out of bounds). It returns TRUE/FALSE. The default implementation uses least significant bit of item data.

    This class should work with all combo box styles (CBS_SIMPLE, CBS_DROPDOWN and CBS_DROPLIST), although it has been thoroughly tested only with CBS_DROPDOWN. The combo box must be marked as CBS_OWNERDRAWFIXED (CBS_OWNERDRAWVARIABLE is possible but would require some changes to the code) and CBS_HASSTRINGS.

    I am interested in hearing any comments.


  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Petr Novotny



    Czech Republic Czech Republic

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    Generalremoving a combo box item during runtime PinmemberS.R.Sasi Kumar1:17 26 Jul '07  
    GeneralChoosing which items to disable PinmemberHe||Fire23:33 29 Jun '06  
    GeneralRe: Choosing which items to disable Pinmemberhengyulo1:12 10 Aug '06  
    GeneralRe: Choosing which items to disable Pinmemberuthamanmcadba1:25 29 Sep '09  
    GeneralProject with ExtendedComboBox Class PinmemberKarli0:48 13 Jan '04  
    GeneralRe: Project with ExtendedComboBox Class PinmemberPabs(Sco)2:55 24 Nov '05  
    Generaldisable item when selecting it Pinmemberbruno leclerc0:16 21 May '03  
    GeneralRe: disable item when selecting it PinmemberlaxmanHCL23:49 8 Apr '05  
    GeneralRe: disable item when selecting it Pinmemberbruno leclerc2:57 11 Apr '05  
    GeneralRe: disable item when selecting it Pinmemberhengyulo1:32 10 Aug '06  
    Generalsimilar control for VB PinmemberManisha20:47 14 Mar '02  
    GeneralCombo Box height PinmemberPane7:23 16 Nov '01  
    GeneralHiding some items in the Combobox PinmemberManjuGeorge4:11 29 Oct '01  
    GeneralMessage Removed PinmemberAnonymous8:32 12 Oct '01  
    GeneralExPropertiesList - commercial troll PinmemberDean Wyant3:34 30 Aug '07  
    GeneralEnable disabled items PinsussManon Perreault3:26 7 Aug '00  
    GeneralRe: Enable disabled items PinsussPetr Novotny3:33 7 Aug '00  
    GeneralBox seams to be too high PinsussDieter Fauth3:07 2 Aug '00  
    GeneralRe: Box seams to be too high (work around) PinsussDieter Fauth0:24 29 Aug '00  
    GeneralRe: Box seams to be too high PinmemberJohn Willcox III8:32 20 Apr '01  
    GeneralBug fix - keys in non-dropped state PinsussRadim Krampol21:44 23 May '00  
    GeneralDoes not work for CBS_DROPDOWNLIST PinsussAndreas Gut23:27 17 Apr '00  
    GeneralRe: Does not work for CBS_DROPDOWNLIST PinsussPetr Novotny23:32 17 Apr '00  
    GeneralRe: Does not work for CBS_DROPDOWNLIST PinsussDieter Fauth3:10 2 Aug '00  
    GeneralRe: Does not work for CBS_DROPDOWNLIST [modified] PinmemberAndy Metcalfe3:02 11 Sep '00  

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Mobile
    Web03 | 2.5.120517.1 | Last Updated 15 Apr 2000
    Article Copyright 2000 by Petr Novotny
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid