我一直在玩 datagridviews 并且出现了一个问题。-> 不会因 CellFormatting 事件而改变单元格背景。我试过这个:
private void dataGridView1_CellFormatting(object sender, dataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name.Equals(dnsList.First<String>()))
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
DataGridViewCell cell = row.Cells[e.ColumnIndex];
cell.Style.BackColor = Color.FromArgb(194, 235, 211);
}
}
效果很好,而这个:
private void ApplyColoring()
{
if (dataGridView1.DataSource != null)
{
foreach (DataGridViewRow dataGridRow in dataGridView1.Rows)
{
DataGridViewCell cell = dataGridRow.Cells[dnsList.First<String>()];
cell.Style.BackColor = Color.FromArgb(194, 235, 211);
}
}
}
调试告诉我一切正常,null-reference-or-whatever-exception-wise...有什么提示吗?