DataTable dt = new DataTable();
dt.Columns.Add("姓名", Type.GetType("System.String"));
dt.Columns.Add("性别", Type.GetType("System.String"));
dt.Columns.Add("年龄", Type.GetType("System.Int32"));
dt.Rows.Add(new object[] { "甲", "男", 22 });
dt.Rows.Add(new object[] { "乙", "女", 20 });
dt.Rows.Add(new object[] { "丙", "女", 21 });
dt.Rows.Add(new object[] { "丁", "女", 22 });
dataGridView1.DataSource = dt;
DataGridViewCheckBoxColumn checkColum = new DataGridViewCheckBoxColumn();
checkColum.HeaderText = "Select";
checkColum.Name = "Select";
checkColum.DataPropertyName = "Select";
checkColum.ReadOnly = false;
checkColum.TrueValue = true ;
checkColum.FalseValue = false;
dataGridView1.Columns.Add(checkColum);
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells["Select"].Selected = true;或者dataGridView1.Rows[i].Cells["Select"].Value = true;
}
网上都是用以上方法,测试发现无效,有经过测试过的方法没?
|