Click here to Skip to main content
13,803,390 members
Click here to Skip to main content
Add your own
alternative version


33 bookmarked
Posted 6 Aug 2000

Read Only ComboBox

, 3 Oct 2000
Rate this:
Please Sign up or sign in to vote.
Show a disabled dropdown style combobox like a read only edit box.
<!-- Link to source file download -->
  • Download source files - 1 Kb
  • <!-- Article image -->

    Sample Image - readonlycombo.jpg


    This is a very quick fix to displaying a disabled combo box as read only. If you have a form with lots of read only edit boxes, the normal disabled combo box looks a bit funny. Read only edit boxes have black text with grey backgrounds. While disabled combo boxes have dark grey text with grey backgrounds. Hard to explain to users.

    This code only works for drop down style combo boxes. This is because I am setting the child edit box as enabled and read only when the parent combo box is disabled.

    When the combo box gets a WM_ENABLE message, check the bEnable flag and call EnableWindow and SetReadOnly for the edit box. A pointer to the edit box is retrieved by just getting the first child window of the combo box, GetWindow(GW_CHILD).

    BEGIN_MESSAGE_MAP(CReadOnlyComboBox, CComboBox)
    void  CReadOnlyComboBox::OnEnable(BOOL bEnable)
    	// Get edit control which happens to be the first child window
    	CEdit* pEdit = (CEdit*)GetWindow(GW_CHILD);
    	// Always have the edit box enabled
    	// Set read only is combo box is disabled

    The only down side to this approach is the text can't be selected with the mouse like a read only edit box.


    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

    Tim McColl
    Software Developer (Senior)
    Australia Australia
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    Generalread only combo boxes Pin
    odesanmi16-Jan-10 15:48
    memberodesanmi16-Jan-10 15:48 
    GeneralUnselectable item in Combo Box - MFC Pin
    Karri Mohan4-Jul-08 4:45
    memberKarri Mohan4-Jul-08 4:45 
    QuestionNice idea, but a small problem. Pin
    harrys123418-Jan-08 10:59
    memberharrys123418-Jan-08 10:59 
    NewsRe: Nice idea, but a small problem. Pin
    harrys123418-Jan-08 14:19
    memberharrys123418-Jan-08 14:19 
    GeneralRe: Nice idea, but a small problem. Pin
    yv323-Jul-08 10:55
    memberyv323-Jul-08 10:55 
    GeneralRe: Nice idea, but a small problem. Pin
    Robin Imrie21-Oct-09 5:08
    professionalRobin Imrie21-Oct-09 5:08 
    GeneralGood article! Pin
    Larpyboy26-Aug-07 15:56
    memberLarpyboy26-Aug-07 15:56 
    QuestionCan Scroll Pin
    8-Dec-00 2:28
    suss8-Dec-00 2:28 
    GeneralFor ATL and or WTL Pin
    Rodger Bernstein8-Oct-00 8:53
    sussRodger Bernstein8-Oct-00 8:53 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Cookies | Terms of Use | Mobile
    Web01 | 2.8.181215.1 | Last Updated 4 Oct 2000
    Article Copyright 2000 by Tim McColl
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid