Click here to Skip to main content
Click here to Skip to main content

A flag editor

, 17 Oct 2002
Rate this:
Please Sign up or sign in to vote.
This piece of code is the implementation of a simple flags editor. It can be used to edit flags in a property grid.

Sample Image - FlagsEditor.gif


This editor displays a dropdown control holding a CheckedListBox with all the values of an enumeration.

Using the FlagsEditor

You just have to put the Editor attributes on an enumeration to link it with the FlagsEditor. A Description attribute can also be added to each value. It will be shown as a tooltip on the CheckedListBox items.

Here is a sample.

public enum EnumerationTest
    [Description("Description for the first tested value.")]
    firstValue = 1,
    [Description("Description for the second tested value.")]
    secondValue = 2,
    [Description("Description for the third tested value.")]
    thirdValue = 4

How does it work ?

The Editor is just one class that inherits UITypeEditor. The behavior of Editor is controlled by two functions.


This function is used for controlling the appearance of the small button in the property grid. In this sample a dropdown arrow will be shown.

public override UITypeEditorEditStyle 
       GetEditStyle(ITypeDescriptorContext context) 
    return UITypeEditorEditStyle.DropDown;


This function is called when the user clicks on the small button.

public override object EditValue(ITypeDescriptorContext context, 
        IServiceProvider provider, object value) 
    if (context != null
        && context.Instance != null
        && provider != null) 

        // Get an instance of the IWindowsFormsEditorService. 
        edSvc = (IWindowsFormsEditorService)provider.GetService

        if (edSvc != null) 
            // Create a CheckedListBox
            clb = new CheckedListBox();


            // Show our CheckedListbox as a DropDownControl. 
            // This methods returns only when
            // the dropdowncontrol is closed

            // return the right enum value
            // corresponding to the result
            return ...

    return value;

The DropDownControl can be closed by calling the edSvc.CloseDropDown() function.

For a complete example, just download the source file.


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

Thierry Bouquain
Web Developer
France France
No Biography provided

Comments and Discussions

GeneralVB.NET Port + Little Extra Feature PinmemberThe_Mega_ZZTer5-Aug-05 6:16 
Generalcant get the zip file PinsussPaul Ashton14-Apr-05 2:10 
GeneralRe: cant get the zip file PinmemberThe_Mega_ZZTer5-Aug-05 6:15 
GeneralThank You PinmemberDave Mc Kenzie14-Oct-04 23:26 
QuestionHow to use this concept for other types? PinmemberDerSebastian4-Oct-04 4:29 
AnswerRe: How to use this concept for other types? Pinmembereschneider1009-Nov-05 13:15 
GeneralNice Job! Pinmemberglusk30-Aug-04 10:52 
GeneralFlag Editor PinmemberFregate18-Dec-03 20:10 
GeneralRe: Flag Editor PinmemberShyH26-Jan-04 21:02 
GeneralIt took... PinmemberJames T. Johnson28-May-03 2:32 
GeneralRe: It took... PinmemberNnamdi Onyeyiri28-May-03 4:45 
GeneralIgnore the people PinmemberPete Bassett6-Dec-02 2:16 
GeneralRe: Ignore the people PinmemberVirender Sandhu9-Feb-03 11:28 
Questionumm ... I second the ... What is this exactly ? PinsussAnonymous18-Oct-02 18:17 
AnswerRe: umm ... I second the ... What is this exactly ? PineditorJames T. Johnson18-Oct-02 18:46 
GeneralRe: umm ... I second the ... What is this exactly ? PinmemberPhilippe Lhoste22-Oct-02 7:32 
GeneralRe: umm ... I second the ... What is this exactly ? Pinmemberstestagg10-Jul-08 3:01 
Questionumm...what is this exactly? PinmemberMarc Clifton18-Oct-02 12:13 
AnswerRe: umm...what is this exactly? PinmemberEd.Poore24-Aug-06 6:09 
GeneralRe: umm...what is this exactly? PinprotectorMarc Clifton24-Aug-06 9:07 
GeneralRe: umm...what is this exactly? PinmemberEd.Poore24-Aug-06 9:19 
GeneralRe: umm...what is this exactly? Pinmemberpeterchen11-Apr-07 4:01 
General!wow PinmemberNorm Almond18-Oct-02 8:56 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150224.1 | Last Updated 18 Oct 2002
Article Copyright 2002 by Thierry Bouquain
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid