You want to limit the number of checked items in a CheckedListBox. What property of CheckedListBox tells you what is checked? Once you have that, is there some way to Count them?
What I want to do is to prevent the selection of another item in the checkbox once the total units textbox has already reached 15. those items with from the checkbox with "-lab" are equivalent to 1 unit and those without "-lab" are equivalent to 2 units.
I made use of this code:
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
int total = 0;
string s = "";
for (int x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++)
s = checkedListBox1.CheckedItems[x].ToString();
if (s.IndexOf("-Lab") != -1)
total += 1;
total += 2;
textBox3.Text = total.ToString();
This is rather embarrassing and disappointing. You have already asked two questions on one project. most of the times it's better to learn from your own mistakes, besides from what I can tell I assume you're a beginner program and probably using VS,SharpDev or some IDE which most probably has support for Intellisense and have access to a book / msdn documentation.
Mate, most collection classes in .NET have one or more properties of counting or enumerating over their collection. given that or your knowledge with loops you can archive whatever is that you're looking for. I won't give you a straight answer but as a hint that control you're using probably has a SelectedIndexes / SelectedItems proteries which in most cases will return an integer which you can using in comparing if you have reached your maximum or not. if you're good you can keep count using event handlers which will notify you each time an item is check or unchecked and then you can disable or do some house keeping you need to do.