可以在DataGridView的RowPrePaint事件中加入代码来实现,例如根据DataGridView1的第2列值的第一个字符内容改变行的背景色为蓝色: Private Sub DataGridView1_RowPrePaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint If Not (DataGridView1.Rows(e.RowIndex).Cells(1).Value Is Nothing) Then If Mid(DataGridView1.Rows(e.RowIndex).Cells(1).Value.ToString,1,1) = "D" Then DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Blue End If End If End Sub------------------------------------------------------------------------------ DataGridView控件的编程技巧在人民邮电出版社出版的书《Visual Basic .NET 2005数据库编程技术与实例》一书中有更精彩的介绍,希望对你有所帮助 详情请见:http://www.ptpress.com.cn/books/Book_Information.asp?BID=16271 ------------------------------------------------------------------------------
参考这里:http://blog.programfan.com/article.asp?id=20195
{
e.Row.Attributes.Add("bgColor", "red");
}
else if(e.Row.Cells[n].Text>"500")
{
e.Row.Attributes.Add("bgColor", "green");
}
Private Sub DataGridView1_RowPrePaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint
If Not (DataGridView1.Rows(e.RowIndex).Cells(1).Value Is Nothing) Then
If Mid(DataGridView1.Rows(e.RowIndex).Cells(1).Value.ToString,1,1) = "D" Then
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Blue
End If
End If
End Sub------------------------------------------------------------------------------
DataGridView控件的编程技巧在人民邮电出版社出版的书《Visual Basic .NET 2005数据库编程技术与实例》一书中有更精彩的介绍,希望对你有所帮助
详情请见:http://www.ptpress.com.cn/books/Book_Information.asp?BID=16271
------------------------------------------------------------------------------