How can I change the value of data lines in the third colomn of the dgv, with this code,I can change the value of all lines in the third column of the dgv but I want only the lines in which I have data.
private void button4_Click(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
dataGridView1.Rows.Add("" + dt.Year.ToString() + "", "En cours", "0");
if (dataGridView1.SelectedRows.Count == 1)
{
DataGridViewRow row = dataGridView1.SelectedRows[0];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
// int ik = (int)dataGridView1.Rows[i].Cells[3].Value;
dataGridView1.Rows[i].Cells[2].Value = 1;
}
}
How can I do it?
Edit: I tried to test the value of every cell in the rows if is it null I will break the foreach :
private void button4_Click(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
dataGridView1.Rows.Add("" + dt.Year.ToString() + "", "En cours", "0");
if (dataGridView1.SelectedRows.Count == 1)
{
DataGridViewRow row = dataGridView1.SelectedRows[0];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
// int ik = (int)dataGridView1.Rows[i].Cells[3].Value;
foreach (DataGridViewRow row1 in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row1.Cells)
{
if (cell.Value != null)
{
dataGridView1.Rows[i].Cells[2].Value = 1;
}
else //if (string.IsNullOrEmpty( cell.Value.ToString()))
{
break;
}
}
}
}
}
}
but I don't know why I still have the same result all the rows have the value "1" in the dataGridView any Help pleaze?