111,107
社区成员




DataTable dt = new DataTable();
dt.Columns.Add("yn");
dt.Rows.Add("y");
dt.Rows.Add("n");
dt.Rows.Add("y");
dt.Rows.Add("y");
dt.Rows.Add("y");
dt.Rows.Add("n");
((DataGridViewCheckBoxColumn)dataGridView1.Columns["你的datagridview中的check列"]).TrueValue = "y";
((DataGridViewCheckBoxColumn)dataGridView1.Columns["你的datagridview中的check列"]).FalseValue = "n";
this.dataGridView1.DataSource = dt;
private void button3_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataColumn aa = new DataColumn("name");
dt.Columns.Add(aa);
dt.Rows.Add("Y");
dt.Rows.Add("N");
dt.Rows.Add("N");
dt.Rows.Add("Y");
((DataGridViewCheckBoxColumn)dataGridView1.Columns[0]).TrueValue = "Y";
((DataGridViewCheckBoxColumn)dataGridView1.Columns[0]).FalseValue = "N";
dataGridView1.DataSource = dt;
}
DataGridViewCheckBoxColumn.TrueValue = "Y"
DataGridViewCheckBoxColumn.FalseValue = "N"
DataGridViewCheckBoxColumn.ThreeState = False
DataTable dt = new DataTable();
dt.Columns.Add("checkcolumns", System.Data.SqlDbType.Bit);
for (int count = 0; count < dt.Rows.Count; count++)
{
if (this.dt.Rows[count]["Y与N的例"].ToString() == "Y")
{
dt.Rows[count]["checkcolumns"] = 1;
}
else
{
dt.Rows[count]["checkcolumns"] = 0;
}
}
//在绑定时把你的Y与N例的数据属性改为checkcolumns
this.dataGridView1.DataSource = dt;
this.dataGridView1.AutoGenerateColumns = false;