我有一個dataGridView和一個按鈕,當我點擊按鈕時,每行的第三個單元格包含值「1」,但我希望只有包含數據的行應在第三列包含「1」 。 我想這個代碼使得那些之前對其進行測試,但結果顯示的圖像:我得到第三列「一」的所有行!
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;
}
}
}
}
}
}
結果:爲幫助
感謝
我希望dataGridView中的每一行在第三列中包含值「1」,只有包含數據的行,但對於其他空行(cell.value == null,有必要把「1」):) – Lina
我需要幫助,請:'( – Lina