Hello,
Lets say we have 6 items in the CheckedListBox.
this.CheckedListBox1.Items.Add("Test1");
this.CheckedListBox1.Items.Add("Test2");
this.CheckedListBox1.Items.Add("Test3");
this.CheckedListBox1.Items.Add("Test4");
this.CheckedListBox1.Items.Add("Test5");
this.CheckedListBox1.Items.Add("Test6");
Now we will show errorprovider when user selects more than 3 values.
CODE
private void CheckedListBox1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
if (this.CheckedListBox1.CheckedItems.Count == 3) {
if (e.CurrentValue == CheckState.Unchecked)
{
this.ErrorProvider1.SetError(this.CheckedListBox1, "Select only 3 values");
e.NewValue = CheckState.Unchecked;
}
else
{
ErrorProvider1.Clear();
}
}
}
I hope this will help.
Regards,
Allen
This post has been edited by allensmith: 4 Aug, 2008 - 01:17 PM