Saturday, 18 May 2013


Step1:

class Employee
    {
        public string ID{ get; set; }
        public string Name{ get; set; }
    }
Step2: Place a checkedListBox on Form.
Step3:
public void bind()
        {
            List<Employee> lis = new List<Employee>();
            for (int i = 0; i < 10; i++)
            {
                Employee obj = new Employee();
                obj.ID = i.ToString();
                obj.Name = "Name:" + i;
                lis.Add(obj);
            }
            checkedListBox1.DataSource = lis.ToList<Employee>();
            checkedListBox1.DisplayMember = "Name";
            checkedListBox1.ValueMember = "ID";

        }

Above method call in Form_Load.

Find the Item checked or not.
checkedListBox1.SetItemChecked(5, true);
Find the checkedList Items:
  foreach (var item in checkedListBox1.CheckedItems)
            {
                var Emp = (Employee)item;
                MessageBox.Show(Emp.ID + ": " + Emp.Name);
            }

No comments:

Post a Comment