DataGridViewCheckBoxColumn chbIsTrue = new DataGridViewCheckBoxColumn();
dataGridView1.DataSource = Human.GetReserve(shopno, state).Tables[0].Copy();
dataGridView1.Columns.Add(chbIsTrue);
chbIsTrue.HeaderText = "通过";
以上的代码让datagridview除了数据之外又多显示了一列DataGridViewCheckBoxColumn
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                if (dataGridView1.Rows[i].Cells["状态"].Value.ToString() == "新申请")
                {
                    chbIsTrue.checked=true;//没有这个属性
                }
                else
                {
                    
                }
            }
请高手指点一下 我如何把它设置为选中啊

解决方案 »

  1.   

    在RowDataBound绑定事件中处理:  OnRowDataBound ="gvList_DataBinding"  public void gvList_DataBinding(object sender, GridViewRowEventArgs e)
      {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          HiddenField hfView = (HiddenField)e.Row.FindControl("dataView");
          HtmlInputCheckBox cbView = (HtmlInputCheckBox)e.Row.FindControl("cbView");
          if (hfView.Value == "1")
          {
            cbView.Checked = true;
            hfViewUsers.Value =  string.IsNullOrEmpty(hfViewUsers.Value)?  cbView.Value: hfViewUsers.Value + "," + cbView.Value;
          }
      }
      

  2.   

    2楼的肯定不行  我这是winfrom 程序
      

  3.   

    DataGridViewCheckBoxColumn chbIsTrue = new DataGridViewCheckBoxColumn();
    chbIsTrue。name=“123”;
    dataGridView1.DataSource = Human.GetReserve(shopno, state).Tables[0].Copy();
    dataGridView1.Columns.Add(chbIsTrue);
    chbIsTrue.HeaderText = "通过";
    以上的代码让datagridview除了数据之外又多显示了一列DataGridViewCheckBoxColumn
    for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    if (dataGridView1.Rows[i].Cells["状态"].Value.ToString() == "新申请")
                    {
                        //chbIsTrue.checked=true;//没有这个属性
    dataGridView1.Rows[i].Cells["123"].Value=true;
                    }
                    else
                    {
                        
                    }
                }
      

  4.   

    你需要改变数据源中的值,而不是设置界面元素。在 Windows Forms 中,所有的 DataGridView 数据操作都需要和数据源进行交互,而不是界面。拿你的代码来说,你需要改变 DataTable 中,CheckBox 所绑定的列的值。