CSkin博客
标题:
datagridview checkbox默认勾选
[打印本页]
作者:
lgqlovexl
时间:
2018-1-27 19:24
标题:
datagridview checkbox默认勾选
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;
}
网上都是用以上方法,测试发现无效,有经过测试过的方法没?
欢迎光临 CSkin博客 (http://bbs.cskin.net/)
Powered by Discuz! X3.2