Csharp/C Sharp by API/System.Windows.Forms/CheckedListBox — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:31, 26 мая 2010

CheckedListBox.CheckOnClick

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.CheckState.Checked

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.CheckState.Indeterminate

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.GetItemCheckState

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.GetItemText

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.ItemCheck

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.Items

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.Items.Add

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.Items.AddRang

 
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

class Form1 : Form {
    public Form1() {
        InitializeComponent();
        this.checkedListBoxPossibleValue.Items.Add("Ten");
    }
    private void buttonMove_Click(object sender, EventArgs e) {
        if (this.checkedListBoxPossibleValue.CheckedItems.Count > 0) {
            this.listBoxSelected.Items.Clear();
            foreach (string item in this.checkedListBoxPossibleValue.CheckedItems) {
                this.listBoxSelected.Items.Add(item.ToString());
            }
            for (int i = 0; i < this.checkedListBoxPossibleValue.Items.Count; i++)
                this.checkedListBoxPossibleValue.SetItemChecked(i, false);
        }
    }
    private void InitializeComponent() {
        this.checkedListBoxPossibleValue = new System.Windows.Forms.CheckedListBox();
        this.buttonMove = new System.Windows.Forms.Button();
        this.listBoxSelected = new System.Windows.Forms.ListBox();
        this.SuspendLayout();
        this.checkedListBoxPossibleValue.CheckOnClick = true;
        this.checkedListBoxPossibleValue.FormattingEnabled = true;
        this.checkedListBoxPossibleValue.Items.AddRange(new object[] {
            "One",
            "Two",
            "Three",
            "Four",
            "Five",
            "Six",
            "Seven",
            "Eight",
            "Nine"});
        this.checkedListBoxPossibleValue.Location = new System.Drawing.Point(13, 13);
        this.checkedListBoxPossibleValue.Name = "checkedListBoxPossibleValue";
        this.checkedListBoxPossibleValue.Size = new System.Drawing.Size(187, 242);
        this.buttonMove.Location = new System.Drawing.Point(207, 129);
        this.buttonMove.Text = "Move";
        this.buttonMove.Click += new System.EventHandler(this.buttonMove_Click);
        this.listBoxSelected.FormattingEnabled = true;
        this.listBoxSelected.Location = new System.Drawing.Point(288, 13);
        this.listBoxSelected.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
        this.listBoxSelected.Size = new System.Drawing.Size(187, 238);
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(492, 273);
        this.Controls.Add(this.listBoxSelected);
        this.Controls.Add(this.buttonMove);
        this.Controls.Add(this.checkedListBoxPossibleValue);
        this.Text = "List Boxes";
        this.ResumeLayout(false);
    }
    private System.Windows.Forms.CheckedListBox checkedListBoxPossibleValue;
    private System.Windows.Forms.Button buttonMove;
    private System.Windows.Forms.ListBox listBoxSelected;
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


CheckedListBox.MultiColumn

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.ScrollAlwaysVisible

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.SelectedIndexChanged

  
using System;
using System.Windows.Forms;
using System.Drawing;
using System.ruponentModel;
 
public class CheckedListBoxDemo:Form{
  CheckedListBox FavLangs;
  GroupBox grpControls;
  Button AddValue;
  Button EditValue;
  Button DeleteValue;
  Button ShowValues;
  TextBox OldValue;
  TextBox NewValue;
  Label OldCaption;
  Label NewCaption;
  CheckBox chkAll;
 
  public CheckedListBoxDemo(){
    grpControls=new GroupBox();
    grpControls.Text="CheckedListBox Demo";
 
    AddValue=new Button();
    AddValue.Text="&Add";
    AddValue.Click+=new EventHandler(Add_Click);
    
    EditValue=new Button();
    EditValue.Text="&Edit";
    EditValue.Click+=new EventHandler(Edit_Click);
    
    DeleteValue=new Button();
    DeleteValue.Text="&Delete";
    DeleteValue.Click+=new EventHandler(Delete_Click);
    
    ShowValues=new Button();
    ShowValues.Text="&Show";
    //ShowValues.Click+=new EventHandler(ShowValues_Click);
    ShowValues.Click+=new EventHandler(Checked_Changed);
    
    OldValue=new TextBox();
    OldValue.ReadOnly=true;
    NewValue=new TextBox();
 
    OldCaption=new Label();
    OldCaption.Text="Old Value:";
    NewCaption=new Label();
    NewCaption.Text="New Value:";
    chkAll=new CheckBox();
    chkAll.Text="Check/UnCheck All";
    chkAll.CheckedChanged+= new EventHandler(Checked_Changed);
    chkAll.Width=175;
 
    OldCaption.Location=new Point(15,15);
    PositionControl(OldCaption,OldValue,true);
    PositionControl(OldCaption,NewCaption,false);
    PositionControl(OldValue,NewValue,false);
    PositionControl(NewCaption,AddValue,false);
    PositionControl(AddValue,EditValue,true);
    PositionControl(EditValue,DeleteValue,true);
    PositionControl(DeleteValue,ShowValues,true);
    PositionControl(AddValue,chkAll,false);
 
    grpControls.Controls.AddRange(new Control[]{OldCaption,OldValue,NewCaption,NewValue,AddValue,EditValue,DeleteValue,ShowValues,chkAll});
    grpControls.Size=new Size(450,200);
 
    FavLangs=new CheckedListBox();
    FavLangs.Location=new Point(10,10);
    FavLangs.SelectedIndexChanged+=new EventHandler(SelectedIndex_Changed);
 
    grpControls.Location=new Point(FavLangs.Left+FavLangs.Width+20,FavLangs.Top);
    this.Controls.AddRange(new Control[]{FavLangs,grpControls});
  }
 
  private void PositionControl(Control source,Control destination,bool CanPlaceHorizontal)
  {
    if(CanPlaceHorizontal){
      destination.Location=new Point(source.Left+source.Width+20,source.Top);
    }else{
      destination.Location=new Point(source.Left,source.Top+source.Height+20);      
    }
  }
 
  private void Add_Click(object sender,EventArgs e){
    ((Button)sender).Text = "aaa";
    
    if(NewValue.Text.Trim()!=""){
      FavLangs.Items.Add(NewValue.Text);
    }else{
      MessageBox.Show("Enter a Value to Add");
    }
  }
 
  private void SelectedIndex_Changed(object sender,EventArgs e){
    OldValue.Text=FavLangs.Items[FavLangs.SelectedIndex].ToString();
  }
 
  private void Edit_Click(object sender,EventArgs e){
    if(FavLangs.SelectedIndex==-1){
      MessageBox.Show("Select a Item to Edit");
    } else{
     if(NewValue.Text.Trim()!=""){
        FavLangs.Items[FavLangs.SelectedIndex]=NewValue.Text;
     }
      else
      {
        MessageBox.Show("Enter a Value to Edit");
      }            
    }
  }
 
  private void Delete_Click(object sender,EventArgs e)
  {
    if(FavLangs.SelectedIndex!=-1)
    {
      FavLangs.Items.RemoveAt(FavLangs.SelectedIndex);
    }
    else
    {
      MessageBox.Show("Select a Item to Delete");
    }
  }
 
  private void ShowValues_Click(object sender,EventArgs e){
    string SelectedValues="The following value(s) are Selected:\n" + new String("-",48) + "\n";
    for(int i=0;i<FavLangs.CheckedItems.Count;i++){
      SelectedValues+=FavLangs.CheckedItems[i].ToString() + "\n";
    }
    MessageBox.Show(SelectedValues);
  }
 
  private void Checked_Changed(object sender,EventArgs e){
      for(int i=0;i<FavLangs.Items.Count;i++){
          FavLangs.SetItemChecked(i,chkAll.Checked);
      }    
  }
 
  public static void Main(){
      Application.Run(new CheckedListBoxDemo());
  }
}


CheckedListBox.SetItemCheckState

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}


CheckedListBox.ThreeDCheckBoxes

 

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
public class CheckedListBoxes : Form
{
  CheckedListBox clb;
  Button btnToggle;
  Button btnClear;
  String str;
  public CheckedListBoxes()
  {
    Size = new Size(300,400);
    this.Load += new EventHandler(this_Load);
    clb = new CheckedListBox();
    clb.Parent = this;
    clb.Location = new Point(10,10);
    clb.Size = new Size(ClientSize.Width - 20, Height - 240);
    clb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
    clb.BorderStyle = BorderStyle.Fixed3D;
    clb.MultiColumn = true;
    clb.ScrollAlwaysVisible = true;
    clb.ThreeDCheckBoxes = true;  
    clb.CheckOnClick = true;
    clb.ItemCheck += new ItemCheckEventHandler(clb_ItemCheck);
    btnToggle = new Button();
    btnToggle.Parent = this;
    btnToggle.Text = "Toggle Indeterminate";
    btnToggle.Size = new Size((int)(Font.Height * .75) * btnToggle.Text.Length, Font.Height + 10);
    btnToggle.Location = new Point( clb.Left, clb.Bottom + 10);
    btnToggle.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnToggle.Click += new System.EventHandler(btnToggle_Click);
    btnClear = new Button();
    btnClear.Parent = this;
    btnClear.Text = "Clear All";
    btnClear.Size = new Size((int)(Font.Height * .75) * btnClear.Text.Length, Font.Height + 10);
    btnClear.Location = new Point(btnToggle.Left, btnToggle.Bottom + 10);
    btnClear.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
    btnClear.Click += new System.EventHandler(btnClear_Click);
    clb.Items.Add("12345");
      clb.Items.Add("67890");      
      clb.Items.Add("7890");      
      clb.Items.Add("890");            
  }  
  static void Main() 
  {
    Application.Run(new CheckedListBoxes());
  }
  private void btnToggle_Click(object sender, EventArgs e)
  {
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      if (clb.GetItemCheckState(i) == CheckState.Checked)
      {
        clb.SetItemCheckState(i, CheckState.Indeterminate);  
      }
      else if (clb.GetItemCheckState(i) == CheckState.Indeterminate)
      {
        clb.SetItemCheckState(i, CheckState.Checked);  
      }
    }  
  }
  private void btnClear_Click(object sender, EventArgs e)
  {
    clb.ClearSelected();
    for (int i = 0; i <= (clb.Items.Count - 1); i++)
    {
      clb.SetItemChecked(i, false);  
    }
  }
  private void clb_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    Console.WriteLine("Current Item:" + clb.GetItemText(clb.Items[e.Index]));
    Console.WriteLine("Current Index:" + e.Index.ToString() );
    Console.WriteLine("Current Value:" + e.CurrentValue.ToString() );
    Console.WriteLine("New Value:" + e.NewValue.ToString() );
  }
  private void clb_SelectedIndexChanged(object sender, EventArgs e)
  {
    Console.WriteLine("Selected Items:" + clb.SelectedItems.Count.ToString() );
    Console.WriteLine("Checked Items:" + clb.CheckedItems.Count.ToString() );
  }
  private void this_Load(object sender, EventArgs e)
  {
    clb.SelectedIndexChanged += new EventHandler(clb_SelectedIndexChanged);
  }
}