2 回答
TA贡献1796条经验 获得超10个赞
不可选、可以设置ReadOnly =true ; 你现在要求是有条件让它可选。那可以在Form_Load 事件遍历整个列、设置 ReadOnly 属性。
代码:
public partial class FormDemo : Form
{
public FormDemo()
{
InitializeComponent();
this.Load += new EventHandler(Form3_Load);
}
void Form3_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("IsTrue", typeof(bool));
table.Columns.Add("Code");
table.Columns.Add("Name");
DataRow row = null;
row = table.NewRow();
row["IsTrue"] = 1;
row["Code"] = "001";
row["nAME"] = "001";
table.Rows.Add(row);
row = table.NewRow();
row["IsTrue"] = 0;
row["Code"] = "002";
row["nAME"] = "002";
table.Rows.Add(row);
row = table.NewRow();
row["IsTrue"] = 1;
row["Code"] = "003";
row["nAME"] = "003";
table.Rows.Add(row);
row = table.NewRow();
row["IsTrue"] = 0;
row["Code"] = "004";
row["nAME"] = "004";
table.Rows.Add(row);
this.dataGridView1.DataSource = table;
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
this.dataGridView1.Rows[i].Cells[0].ReadOnly = true;
}
}
}
- 2 回答
- 0 关注
- 659 浏览
添加回答
举报