Get Check Status Of A CheckedListBox Item Using Text Instead Of Index
There was a question raised on visual basic forums if you can access an item through it's name rather than index to get it's checked status. My suggestion was to implement a custom control. However, one of the resident MVP in that forum has a better solution using extension method which is simple yet elegant. Below are the extension methods in VB.NET and C#. VB.NET Module CheckedListBoxExtensions <Extension()> Function GetItemChecked( ByVal source As CheckedListBox, ByVal text As String ) As Boolean Dim item = source.Items.Cast( Of Object )().FirstOrDefault(Function(o) source.GetItemText(o) = text) Dim index = source.Items.IndexOf(item) Return source.GetItemChecked(index) End Function End Module C#.NET public static class CheckedListBoxExtensions { public static bool GetItemChecked( this CheckedListBox source, string text) { var item = source.Items.Cast< object >()