【问题标题】:I can't disable checkbox?我不能禁用复选框?
【发布时间】:2016-02-07 04:41:41
【问题描述】:

我无法禁用复选框...

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;
            }
        }
    }
}

【问题讨论】:

标签: c# checkbox


【解决方案1】:

您的代码看起来不错,您是否要将复选框的 visibilitychecked state 设置为 false,而不是禁用它?您是想让它不可见还是不选中?

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

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

EnabledCheckedVisible 有什么区别?

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

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

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

【讨论】:

  • 但是当我从预订了不同座位的表格中选择另一辆巴士时,对应于该座位的复选框没有禁用
  • 它是一个巴士预订项目,25个座位的巴士用复选框表示,复选框(S1,S2........S25),选中并sumit保存在数据库逗号中分开,例如 S1,S2。但是当为另一个预订选择相同的巴士时,已经选择的座位必须在表单加载时禁用(这是成功的)..我在同一页面上有一个组合框和一个搜索按钮,使我能够搜索更多巴士在同一日期同一地点,
  • 当我选择另一辆公共汽车时,我希望禁用已经为该公共汽车预订的座位以及可以启用的座位.....我的问题出在那儿,它没有禁用...... .
  • 好吧,如果成功的话,我想你应该在表单加载中做同样的事情。每次你刷新组合框/用你的元素填充它时,你应该禁用那些被禁用的..不能真正帮助你,因为我不明白你的大部分解释..
猜你喜欢
  • 1970-01-01
  • 2015-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多