Home > DeveloperSection > Forums > CheckListBox in C#
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    June-15-2013 5:25 AM

 C# C# 
Ratings:


 2 Reply(s)
 1305  View(s)
Rate this:
Hi Experts,

How can I add value in CheckListBox using C#?

Thanks in advance.




Sumit Kesarwani

Total Post:378

Points:2694
Posted on    June-15-2013 7:08 AM

Hi Ankita,

You can use the following code:

using System;

using System.Drawing;

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            checkedListBox1.Items.Add("Sunday", CheckState.Checked);

            checkedListBox1.Items.Add("Monday", CheckState.Unchecked);

            checkedListBox1.Items.Add("Tuesday", CheckState.Indeterminate);

            checkedListBox1.Items.Add("Wednesday", CheckState.Checked);

            checkedListBox1.Items.Add("Thursday", CheckState.Unchecked);

            checkedListBox1.Items.Add("Friday", CheckState.Indeterminate);

            checkedListBox1.Items.Add("Saturday", CheckState.Indeterminate);

        }

    }

}


Manmohan Jha

Total Post:35

Points:245
Posted on    July-24-2013 3:30 AM

private void Form1_Load(object sender, EventArgs e)

{

  checkedListBox1.Items.Add("Sunday"false);

  checkedListBox1.Items.Add("Monday"false);

  checkedListBox1.Items.Add("Tuesday"false);

  checkedListBox1.Items.Add("Wednesday"false);

  checkedListBox1.Items.Add("Thursday"false);

  checkedListBox1.Items.Add("Friday"false);

  checkedListBox1.Items.Add("Saturday"false);

try

{

int index = checkedListBox1.Items.IndexOf(DateTime.Now.ToString("MMMM-yy"));

checkedListBox1.SetItemChecked(index, true);

}

catch (Exception) { }

}


Don't want to miss updates? Please click the below button!

Follow MindStick