Checkbox in Datagridview C#

Asked

Viewed 756 times

1

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

dt.rows.add(?);

  • Could you explain your situation a little better? This list of students is the one on DataGridView or it will come from somewhere else and you will compare with the values of DataGridView? Add a little more to your question that I might be able to help you.

2 answers

1

This code scans a gridview and mark/enable the state of checkbox Use 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;
  }
  • Doesn’t solve my problem, thanks

0

I’m guessing it’s a datatable of the Student’s presence, 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 line from that date. Ex:

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

dt.Rows.Add(r);

If Datatable is 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.