简体   繁体   中英

How can I change data type of a DataGridView's column to CheckBox?

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

This did not work:

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

You need to add an actual checkbox column:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM