Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Check a check box in a windows datagridview

I have a unbound column in a datagridview. I am unable to check a check box in the grid. Here is my code.

DataSet dataSet = new DataSet();

SqlCommand selectCommand = new SqlCommand("sp_GetTerminalType", sqlConn);
//SELECTion via a stored procedure
selectCommand.CommandType = CommandType.StoredProcedure;

SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = selectCommand;
DataTable dataTable = new DataTable();
dataAdapter.Fill(dataTable);
bindingSource.DataSource = dataTable;

dataGridView.DataSource = bindingSource;

dataGridView.Columns["Column0"].Visible = false;
dataGridView.Columns[1].HeaderText = "Column1";
dataGridView.Columns[1].MinimumWidth = 85;

////unbound columns
DataGridViewCheckBoxColumn TimeAttendance = new DataGridViewCheckBoxColumn(false);
TimeAttendance.HeaderText = "Column2";
dataGridView.Columns.Insert(2, Column2);
dataGridView.Columns[2].MinimumWidth = 50;
dataGridView.Columns[2].Name = "Column2";

//To check a column

foreach (DataGridViewRow row in dataGridView.Rows)
{
row.Cells[2].Value = true;

}
Sign In or Register to comment.