WinForms – How to get CheckedListBox selected values

A CheckedListBox is a list control with multiple checkboxes. This allows the user to check multiple boxes at once.

How can I can get all the values they selected? By looping through the CheckedListBox.CheckedItems collection. See the UI and Code examples below.


Here’s the form with a CheckedListBox with some selected items:

WinForms - A form with a CheckedListBox control showing several programming languages, with a few of them selected


Here’s the code for looping through the selected CheckedListBox items:

using System; using System.Collections.Generic; using System.Windows.Forms; namespace CheckedListBoxSelector { public partial class frmProgrammingLangs : Form { public frmProgrammingLangs() { InitializeComponent(); } private void btnSubmit_Click(object sender, EventArgs e) { var selectedLangs = new List<string>(); foreach(var lang in clbLanguages.CheckedItems) { selectedLangs.Add(lang.ToString()); } lblResult.Text = $"You selected: {string.Join(", ", selectedLangs)}"; } } }
Code language: C# (cs)

Leave a Comment