Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

An OwnerDraw ComboBox with CheckBoxes in the Drop-Down

, 24 May 2007
An OwnerDraw ComboBox with CheckBoxes in the Drop-Down
checkcombobox.zip
CheckComboBox
bin
Release
CheckBoxCombo.exe
CheckBoxCombo.pdb
CheckComboBox.exe
CheckComboBox.pdb
CheckComboBox.vshost.exe
Properties
Settings.settings
CheckComboBox.suo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CheckBoxCombo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // add three check box items to the combo box and set their checked states to true
            checkComboBox1.Items.Add(new CheckComboBox.CheckComboBoxItem("One", true));
            checkComboBox1.Items.Add(new CheckComboBox.CheckComboBoxItem("Two", true));
            checkComboBox1.Items.Add(new CheckComboBox.CheckComboBoxItem("Three", true));

            // disable the checkboxes so the user can't edit them
            checkBox1.Enabled = false;
            checkBox2.Enabled = false;
            checkBox3.Enabled = false;

            // wire up the check state changed event
            this.checkComboBox1.CheckStateChanged += new System.EventHandler(this.checkComboBox1_CheckStateChanged);

        }

        // this message handler gets called when the user checks/unchecks an item the combo box
        private void checkComboBox1_CheckStateChanged(object sender, EventArgs e)
        {
            if (sender is CheckComboBox.CheckComboBoxItem)
            {
                CheckComboBox.CheckComboBoxItem item = (CheckComboBox.CheckComboBoxItem)sender;
                switch (item.Text)
                {
                    case "One":
                        checkBox1.Checked = item.CheckState;
                        break;
                    case "Two":
                        checkBox2.Checked = item.CheckState;
                        break;
                    case "Three":
                        checkBox3.Checked = item.CheckState;
                        break;
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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

Share

About the Author

Derek Viljoen
Software Developer (Senior)
United States United States
Developer with over twenty years of coding for profit, and innumerable years before that of doing it at a loss.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 24 May 2007
Article Copyright 2007 by Derek Viljoen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid