using System; using System.Windows.Forms; namespace clbTestIndeterminate { public class ClbTestForm : Form { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null)) components.Dispose(); base.Dispose(disposing); } private void InitializeComponent() { this.checkedListBox1 = new System.Windows.Forms.CheckedListBox(); this.SuspendLayout(); // // checkedListBox1 // this.checkedListBox1.CheckOnClick = true; this.checkedListBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.checkedListBox1.FormattingEnabled = true; this.checkedListBox1.Location = new System.Drawing.Point(0, 0); this.checkedListBox1.Name = "checkedListBox1"; this.checkedListBox1.Size = new System.Drawing.Size(292, 259); this.checkedListBox1.TabIndex = 0; this.checkedListBox1.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.checkedListBox1_ItemCheck); // // ClbTestForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.checkedListBox1); this.Name = "ClbTestForm"; this.Text = "ClbTestForm"; this.ResumeLayout(false); } void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { if (e.CurrentValue == CheckState.Indeterminate) e.NewValue = e.CurrentValue; } private System.Windows.Forms.CheckedListBox checkedListBox1; public ClbTestForm() { InitializeComponent(); FillIt(8); } private void FillIt(int n) { for (int i = 0; i < n; i++) if (i % 3 == 0) checkedListBox1.Items.Add(new intCarrier(i), CheckState.Checked); else if (i % 3 == 1) checkedListBox1.Items.Add(new intCarrier(i), CheckState.Unchecked); else checkedListBox1.Items.Add(new intCarrier(i), CheckState.Indeterminate); } } // silly helper class public class intCarrier { int m_int = 0; public override string ToString() { return "Number " + m_int.ToString(); } public intCarrier(int n) { m_int = n; } } static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ClbTestForm()); } } }