Reputation: 575
I'm using winforms and i'm pretty new to it,
can any one help me with:
How to make the last added item to a checkedlistbox automatically selected?
Every new item I add to the checkedlistbox, i want it to be selected.
Thank you!
Nadav
Upvotes: 0
Views: 853
Reputation: 5358
In your code, add this line after you add an item:
checkedlistbox1.SelectedIndex = checkedlistbox1.Items.Count-1
Upvotes: 1
Reputation: 8786
work with and use ControlAdded
event of your checkedListBox Items.count-1
to get the last item added.
Upvotes: 1
Reputation: 34489
Well you can do a number of things:
1) Set the checked state of the item when you add it to the CheckedListBox manually.
CheckedListBoxItem cbl = new CheckedListBoxItem ();
this.checkListBox.Items.Add(cbl);
clb.Checked = true;
2) Create a sub-class of the CheckedListBox and override the 'Add' method to check the item just before adding it.
3) Create a sub-class of the CheckedListBox that exposes an ItemAdded event, wire up to that event and then set the checked state of the item.
Upvotes: 2