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 關注
- 698 瀏覽
添加回答
舉報