private void DGData_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
DataRow dr = DTData.Rows[e.RowIndex];
for (int i = 0; i < DTData.Columns.Count; i++)
{
if (i == 9)
{
if (dr[i].ToString() == "1" || dr[i].ToString() == "2")
{
var dataGridViewCellStyle =
new DataGridViewCellStyle(DGData.DefaultCellStyle)
{
BackColor = Color.Red
};
//第五列的某行赋背景色 dataGridView1[e.ColumnIndex, e.RowIndex].Style
DGData[5, e.RowIndex].Style = dataGridViewCellStyle;
}
}
else
{
if (e.ColumnIndex == i)
{
e.Value = dr[i];
}
}
}
}
标签:Style,CellValueNeeded,ColumnIndex,c#,单元格,RowIndex,dr,DGData From: https://www.cnblogs.com/lypstudy/p/16934522.html