0

有没有办法在同一个单元格中使用 2 种不同的颜色DataGridView?我正在使用 vb.net 2010。

4

1 回答 1

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

于 2012-11-01T22:14:12.750 回答