日期:2014-05-19  浏览次数:20717 次

=====>>>>DataGridView中如何改变特定一行的背景色
有人提过,但发现方法有问题。
特开帖请大虾们进来请几句。

------解决方案--------------------
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name.Equals( "Sex "))
{
if (e.Value== "女 ")
{
e.CellStyle.BackColor =Color.Red;
}

}
}
------解决方案--------------------
'第0行第1列的背景色---红色 ,方法一
sGrid.Rows(0).Cells(1).Style .BackColor=Color.Red
'第1行的背景色---红色
sGrid.Rows(1).DefaultCellStyle.BackColor = Color.Red

方法二
If not sGrid.EditingControl Is Nothing Then
'设置当前编辑列的背景色
sGrid.EditingControl.BackColor = Color.Red
end if