65.9K
CodeProject is changing. Read more.
Home

CheckListBox Based on ListBox that Supports ReadOnly

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.22/5 (3 votes)

Nov 8, 2007

CPOL
viewsIcon

46091

downloadIcon

896

Extended ListBox which supports CheckBox in Normal and ReadOnly mode

Screenshot - CheckListBox_demo.jpg

Introduction

This is based on this article where I extended the code provided by Zhi-Xin Ye in the post to create a CheckListBox that supports ReadOnly unlike CheckedListBox control which can only be disabled.

Using the Code

The demo project contains the code as follows:

private void Form1_Load(object sender, EventArgs e)
{
    //ReadOnly CheckListBox
    checkListBox1.BackColor = Color.FromKnownColor(KnownColor.ControlLight);
    checkListBox1.SelectionMode = SelectionMode.None;
    CheckBox[] boxes = new CheckBox[100];
    for (int i = 0; i < 100; i++)
    {
        CheckBox box = new CheckBox();
        box.Checked = true;
        box.Enabled = false;
        box.Text = "box" + i.ToString();
        boxes[i] = box;
    }
    checkListBox1.AddCheckBoxes(boxes);
    //Normal CheckListBox
    boxes = new CheckBox[100];
    for (int i = 0; i < 100; i++)
    {
        CheckBox box = new CheckBox();
        box.Text = "box" + i.ToString();
        boxes[i] = box;
    }
    checkListBox2.AddCheckBoxes(boxes);
} 

Points of Interest

Like I mentioned, mouse wheel scroll is quite slow and there's flickering when I use scrollbar. This is just a start. Hopefully I will be able to make it better in future.

History

  • 1.0 Created