Home Ask Login Register

Developers Planet

Your answer is one click away!

Shyam February 2016

I can't disable checkbox?

I can't disable checkbox...

public  void seat_reser_Load(object sender, EventArgs e)
    string asd = "";

    DataTable dt = ob.dataview("Select * from seat_res where bus_id='"+ bus_select.Id+"'and date='"+bus_select.date +"'");

    foreach (DataRow d in dt.Rows)
        asd += d[2].ToString();    // d[2] is seat column

    box[0] = CheckBox1;
    box[1] = CheckBox2;
    box[2] = checkBox3;
    box[3] = checkBox4;
    box[4] = checkBox5;
    box[5] = checkBox6;
    box[6] = checkBox7;
    box[7] = checkBox8;
    box[8] = checkBox9;
    box[9] = checkBox10;
    box[10] = checkBox11;
    box[11] = checkBox12;
    box[12] = checkBox13;
    box[13] = checkBox14;
    box[14] = checkBox15;
    box[15] = checkBox16;
    box[16] = checkBox17;
    box[17] = checkBox18;
    box[18] = checkBox19;
    box[19] = checkBox20;
    box[20] = checkBox21;
    box[21] = checkBox22;
    box[22] = checkBox23;
    box[23] = checkBox24;
    box[24] = checkBox25;

    for (int h = 0; h < box.Length; h++)
        box[h].Enabled = true;

    string[] n = asd.Split(',');

    for (int i = 0; i < n.Length; i++)
        for (int j = 0; j < box.Length; j++)
            if (n[i] == box[j].Text)
                box[j].Enabled = false;
            else if (!(box[j].Enabled == false))
                box[j].Enabled = true;


Peroxy February 2016

Your code seems fine, did you want to set the checkbox's visibility or checked state to false, instead of disabling it? Did you want to make it invisible or simply unchecked?

In that case you might want to change your usage of Enabled to Visible or Checked, for example, like this:

box[h].Visible = false;
box[h].Checked = false;

What's the difference between Enabled, Checked and Visible?

Enabled - this will enable/disable the checkbox, you cannot check or uncheck the checkbox if it is disabled, however, the checkbox will still be visible on screen

Checked - this will check/uncheck the checkbox, it's identical to user actually clicking the checkbox

Visible - this will make the checkbox visible/invisible, so that user cannot see the control, nor can he click on it or interact with it in any way

Post Status

Asked in February 2016
Viewed 3,828 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life