I have DataGridView bound by a datatable i have checkboxes to the same.
I want to navigate or loop through the the datagridview and check mark these checkboxes ,Below is the syntax i use .
foreach(DataGridViewRow dr in dgvColumns.Rows)
{
DataGridViewCheckBoxCell checkCell =
(DataGridViewCheckBoxCell)dr.Cells["CheckBoxes"];
checkCell.Value=1;
//Also tried checkCell.Selected=true;
//Nothing seems to have worked.!
}
This looks like it does what you require. I'm new to all this so sorry if I have answered incorrectly. Just trying to help.
Something along the lines of:
The following worked for me, it checked the checkboxes perfectly :)
the row that is selected its value do not get passed to the underlying datasource so do not get saved. the datasource is Datatable. Its problemof datagridview.
If it is bound to a
DataTable
, can you not work on the model (the table) instead? TheDataGridView
is a view...Try looping over the rows in the table, setting the values. For example (below) - note that I don't update the
DataGridView
- just theDataTable
: