【问题标题】:How can I change data type of a DataGridView's column to CheckBox?如何将 DataGridView 列的数据类型更改为 CheckBox?
【发布时间】:2011-04-10 11:43:33
【问题描述】:
MySqlDataAdapter da = new MySqlDataAdapter("select * from mytable", con);

DataSet ds = new DataSet();

ds.Clear();
da.Fill(ds);

dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Columns["id"].Visible = false;
dataGridView1.Columns["chk"].HeaderText ="Check";       

这不起作用:

dataGridView1.Columns["chk"].CellTemplate = new DataGridViewCheckBoxCell();

【问题讨论】:

  • 你的字段的数据类型应该是bit,所以你不需要创建一个DataGridViewCheckBoxCell,如果正确的话:)

标签: c# mysql datagrid


【解决方案1】:

您需要添加一个实际的复选框列:

DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
dataGridView1.Columns.Add(checkColumn);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    相关资源
    最近更新 更多