我有一個DataGridView在一個WinForm,我添加到DataGrid有一個複選框列使用我在這裏看到一個代碼:的DataGridView用默認值的複選框選中
DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
{
column.HeaderText = "Export";
column.Name = "Export";
column.AutoSizeMode =
DataGridViewAutoSizeColumnMode.DisplayedCells;
column.FlatStyle = FlatStyle.Standard;
column.CellTemplate = new DataGridViewCheckBoxCell(false);
column.CellTemplate.Style.BackColor = Color.White;
}
gStudyTable.Columns.Insert(0, column);
這個工作,但我想要的複選框作爲默認鋸檢查我補充說:
foreach (DataGridViewRow row in gStudyTable.Rows)
{
row.Cells[0].Value = true;
}
但複選框col仍未選中。我使用集合作爲數據源,並在添加數據源後更改列的值。
您可以嘗試更改數據源的集合而不是單元格值本身。像'dataSourceCollection [0] =。出口等TRUE' ... –
複選框是不是我的數據源 – meirrav
可以,只要您的數據網格DataBindingComplete引發的事件複選框值設置爲true的一部分:HTTP://social.msdn。 microsoft.com/Forums/en/csharplanguage/thread/2c7fe077-095e-472f-9833-c0633eb7035f – Mate