private const string SELECT_NOW = "Select_Now"; private void dg_DataSourceChanged(object sender, EventArgs e) { if (dg.DataSource == null) return; DataGridViewCheckBoxColumn C = new DataGridViewCheckBoxColumn(); C.Name = SELECT_NOW; C.ReadOnly = true; dg.Columns.Add(C); C.DisplayIndex = 0; foreach (DataGridViewRow r in dg.Rows) { T item = (T)r.DataBoundItem; r.Cells[SELECT_NOW].Value = true; } }
When binding a customer collection to a datagridview, I try to use the DataSourceChanged event to add an unbound column (checkbox column) named "Select_Now".
I am setting the initial value to "true" for each row in this sample (although the production code is more complicated).
I set breakpoints to make sure the code is looping through all the rows, setting the value to true on every row.
When this is done, the user sees the bound grid fully populuated, except no checkmarks! And if he clicks on a cell (which I capture in the cellClick event), the cell.Value is neither true nor false but null/nothing. Why?