在DataGridView中的列头添加复选框

DataTable dt;(DataGridView绑定的DataTable) DataGridView dgView; dt.Columns.Add("check", typeof(bool)); dgView.Columns.Clear(); dgView.AutoGenerateColumns = false; dgView.DataSource = dt; DataGridViewCheckBoxColumn dtCheck = new DataGridViewCheckBoxColumn(); //(注意这里是DataGridViewCheckBoxColumn而不是DataGridViewTextBoxColumn) dtCheck.DataPropertyName = "check"; dtCheck.HeaderText = ""; dgView.Columns.Add(dtCheck); dgView.Columns[0].Width = 30; 

 

你可能感兴趣的:(在DataGridView中的列头添加复选框)