i want to disable few check boxes in a checkedlistbox. what should i do?

Recommended Answers

All 4 Replies

private void CheckBoxListTest_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            for (int j = 0; j < 20; j++)
            {
                dt.Rows.Add("checkbox" + j.ToString());
            }

            CheckBox[] cks = new CheckBox[dt.Rows.Count];
            for (int j = 0; j < dt.Rows.Count; j++)
            {
                cks[j] = new CheckBox();
                cks[j].Text = "";
                cks[j].Checked = true;
              cks[j].Enabled = false;
                cks[j].Height = this.listBox1.ItemHeight;
                cks[j].Width = 15;
                cks[j].Location = new Point(0, this.listBox1.ItemHeight * j);
                this.listBox1.Controls.Add(cks[j]);
                this.listBox1.Items.Add(dt.Rows[j]["name"].ToString());
            }
            this.listBox1.DrawMode = DrawMode.OwnerDrawFixed;
            this.listBox1.DrawItem += new DrawItemEventHandler(listBox1_DrawItem);
        }

if my checklistbox contains 112 items. what should i do to disable item 100 and 101, without increasing number of items?

i have 112 items in checklist box.i want to disable items from 48 to 112.please help me

As pritishdeshmuk mentioned ,

just add the condition

if (j <= 10)
                     {
                         for (int j1 = j; j1 < 20; j1++)
                         {
                             cks[j].Enabled = false;
                         }
                     }

Hope this will help you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.