Kiểm tra checkbox của 1 hàng dataGridview C#
if (e.ColumnIndex == 0) //Cột chứa checkbox
{ //When you check
if (Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[0].EditedFormattedValue) == true)
{
//EXAMPLE OF OTHER CODE
if ((dataGridView1.CurrentRow.Index) == 0) //Kiểm tra checkbox ở hàng đầu tiên
{
dataGridView1.Rows[e.RowIndex].Cells[2].Value = DateTime.Now.ToShortDateString();
MessageBox.Show("Index: " + dataGridView1.CurrentRow.Index);
//SET BY CODE THE CHECK BOX
dataGridView1.Rows[e.RowIndex].Cells[1].Value = 1;
}
}
else //When you decheck
{
dataGridView1.Rows[e.RowIndex].Cells[2].Value = String.Empty;
//SET BY CODE THE CHECK BOX
dataGridView1.Rows[e.RowIndex].Cells[1].Value = 0;
}
}
Đăng nhận xét