C# dataGricview 加选择框
DataGridViewCheckBoxColumn columncb = new DataGridViewCheckBoxColumn();
columncb.HeaderText = "选择";
columncb.Width = 50;
columncb.Name = "cb_check";
columncb.TrueValue = true;
columncb.FalseValue = false;
//column9.DataPropertyName = "IsScienceNature";
columncb.DataPropertyName = "IsChecked";
grdData.Columns.Add(columncb);
private void SetAllRowChecked()
{
// DataGridCell cel=(sender as DataGridCell).
int count = Convert.ToInt16(this.grdData.Rows.Count.ToString());
for (int i = 0; i < count; i++)
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)grdData.Rows[i].Cells["cb_check"];
Boolean flag = Convert.ToBoolean(checkCell.Value);
if (flag == false) //查找被选择的数据行
{
checkCell.Value = true;
}
continue;
}
}