Hello everyone,
I am facing a problem with C# code. The problem is I have developed a form with DataGridView Control. In that grid view at the last cell of each row I have positioned a DataGridViewCheckBoxColumn. Now I wish to set some data in the DataGridViewTextBoxColumn of each row when I check the checkbox and when I uncheck the checkbox the data from that row of each text box column will be clear. I can set the data in each row to check the check box of that row but when I uncheck that check box the data is not set empty. Will you please help me to find the solution for this problem. For your better understanding I am sending the code. Please help me to fix the problem.
Thanks.
Code is:
int clmnIndex = e.ColumnIndex;
int rowIndex = e.RowIndex;
if (clmnIndex == 8)
{
DataGridViewCheckBoxCell chkBox =
(DataGridViewCheckBoxCell)dgvAttendance.Rows[rowIndex].Cells[8];
if (chkBox.Value == chkBox.TrueValue)
{
if (dgvAttendance.Rows[rowIndex].Cells[7].Value == null)
{
dgvAttendance.Rows[rowIndex].Cells[3].Value = DateTime.Now.ToString("MMM dd, yyyy");
dgvAttendance.Rows[rowIndex].Cells[4].Value = DateTime.Now.ToString("HH:mm:ss");
dgvAttendance.Rows[rowIndex].Cells[7].Value = "CheckIn";
}
else
{
dgvAttendance.Rows[rowIndex].Cells[5].Value = DateTime.Now.ToString("HH:mm:ss");
}
}
else if (chkBox.Value == chkBox.FalseValue)
{
if (dgvAttendance.Rows[rowIndex].Cells[7].Value == null)
{
dgvAttendance.Rows[rowIndex].Cells[3].Value = string.Empty;
dgvAttendance.Rows[rowIndex].Cells[4].Value = string.Empty;
dgvAttendance.Rows[rowIndex].Cells[7].Value = string.Empty;
}
else
{
dgvAttendance.Rows[rowIndex].Cells[5].Value = string.Empty;
}
}