我无法禁用复选框

本文关键字:复选框 | 更新日期: 2023-09-27 18:33:34

我无法禁用复选框...

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
        asd+=",";
    }
    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;
                j++;
            }
            else if (!(box[j].Enabled == false))
            {
                box[j].Enabled = true;
            }
        }
    }
}

我无法禁用复选框

您的代码似乎很好,您是否要将复选框的可见性选中状态设置为 false,而不是禁用它?您想让它不可见还是根本不选中?

在这种情况下,您可能希望将Enabled的用法更改为 VisibleChecked ,例如,如下所示:

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

EnabledCheckedVisible有什么区别?

Enabled - 这将启用/禁用该复选框,如果该复选框被禁用,则无法选中或取消选中该复选框,但是,该复选框仍将在屏幕上可见

Checked - 这将选中/取消选中复选框,这与用户实际单击复选框相同

Visible - 这将使复选框可见/不可见,以便用户无法看到控件,也无法单击它或以任何方式与之交互