有没有办法在DataGridView
的同一个单元格中使用2种不同的颜色?我正在使用vb.net 2010。
答案 0 :(得分:0)
将代码放入DataGridView.CellFormatting事件
Private Sub dataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As DataGridViewCellFormattingEventArgs) _
Handles dataGridView1.CellFormatting
' If the column is the Artist column, check the
' value.
If Me.dataGridView1.Columns(e.ColumnIndex).Name _
= "Artist" Then
If e.Value IsNot Nothing Then
' Check for the string "pink" in the cell.
Dim stringValue As String = _
CType(e.Value, String)
stringValue = stringValue.ToLower()
If ((stringValue.IndexOf("pink") > -1)) Then
e.CellStyle.BackColor = Color.Pink
End If
End If
ElseIf Me.dataGridView1.Columns(e.ColumnIndex).Name _
= "Release Date" Then
ShortFormDateFormat(e)
End If
End Sub
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellformatting.aspx