我需要为DataGridView中的特定单元格上色。我试图做,但是没有用。
dataGridView1.Rows[1].Cells[1].Style.BackColor = Color.Red;
但是对于整个专栏来说...
dataGridView1.Columns[2].DefaultCellStyle.BackColor = Color.Red;
但是我需要一个牢房,如果你能帮忙的话,谢谢
尝试这个
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridViewCellStyle MakeItRed = new DataGridViewCellStyle();
MakeItRed.BackColor = Color.Red;
//make a whole column red
dataGridView1.Columns[1].DefaultCellStyle = MakeItRed;
//make a specific cell red
DataGridViewRow row2 = dataGridView1.Rows[2];
row2.Cells[2].Style = MakeItRed;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句