Tôi muốn thay đổi màu nền của hàng DGV dựa trên điều kiện cụ thể khi tải ngay cả trong Biểu mẫu Windows. Nhưng tôi không thể thấy bất kỳ sự thay đổi màu nào đối với bất kỳ hàng nào của DGV. Bất cứ ai có thể cho tôi biết làm thế nào tôi có thể giải quyết vấn đề này?Màu nền của hàng DataGridView không thay đổi
private void frmSecondaryPumps_Load(object sender, EventArgs e)
{
try
{
DataTable dt = DeviceData.BindData("SECONDARY_PUMPS".ToUpper());
dataGridView1.DataSource = dt;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
if (row.Cells[column.Name] != null)
{
if (row.Cells[column.Name].Value.ToString() == "ON")
row.DefaultCellStyle.BackColor = System.Drawing.Color.Green;
if (row.Cells[column.Name].Value.ToString() == "OFF")
row.DefaultCellStyle.BackColor = System.Drawing.Color.Red;
}
}
}
dataGridView1.Refresh();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
tại sao không thiết' BackColor' thay vì 'ForeColor' – V4Vendetta
tôi đã cố gắng này là tốt, nhưng tôi có thể' t thấy bất kỳ thay đổi nào về màu hàng trong bất kỳ hàng nào của DGV – Stardust