Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
i have a checkboxlist n its item are populated from database using a datareader.

when the form contains this checkboxlist is loaded. i want the last item of this checkboxlist to be checked/selected by default.

and when i delete that checked item, the consecutive upper item should be checked.

Any hint or code snippet would be appreciated.

thanks in advance.
Posted

1 solution

Well, check it right after you populate it. How can this ever be a problem? For this purpose, use System.Windows.Forms.CheckedListBox.SetItemChecked(index, true). For index, use Items.Count.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.aspx[^], http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.setitemchecked.aspx[^].

—SA
 
Share this answer
 
Comments
fcronin 12-Jul-11 20:43pm    
Good... but perhaps Items.Count - 1 for index... ;)
sanomama 12-Jul-11 20:43pm    
thanks. bt checkboxlist.items.count-1 is needed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900