Checkbox in DatagridView C #

0

Good afternoon. I have a datagrid view with a column of type checkbox, tied to a DataTable with the column of type checkbox as well. My problem is this: I have to go through a presence list, if the student is present, I have to set the check to true, otherwise I will not do anything. How to do this?

dt.rows.add (?);

    
asked by anonymous 18.04.2016 / 18:50

2 answers

0

This code scans a gridview and marks / enables the status of checkbox Based on this example to solve your problem:

DataGridView dgv = new DataGridView();
for (int i = 0; i < dgv.RowCount; i++)
  {
     DataGridViewRow row = dgv.Rows[i];
     dgv.Rows[i].Cells["NomeDaColunaDoCheckBox"].Value = true;
  }
    
18.04.2016 / 19:10
0

I imagine it to be a Student's DataTable, with the following structure:

-|Data      |Presenca
1|02/05/2017|true
2|01/05/2017|false

You will scroll through the attendance list, and if you find the student, you will add a row for that date. Ex:

DataRow r = dt.NewRow();
r["Data"] = DateTime.Now;
r["Presenca"] = true;

dt.Rows.Add(r);

If the DataTable is as GridView DataSource:

DataTable dt = (DataTable)Grid.DataSource;
DataRow r = dt.NewRow();
r["Data"] = DateTime.Now;
r["Presenca"] = true;

dt.Rows.Add(r);

Grid.DataSource = dt;
    
02.05.2017 / 20:33