2012-11-01 101 views
0

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

+0

什么样的颜色?文本颜色,背景颜色等。 – peroija

+0

字体颜色,一行黑色和第二行红色 – nnopazo

+0

听起来像这里的问题是针对类似的东西? http://stackoverflow.com/questions/11828281/vb-net-color-first-char-in-cell/11828960#11828960 –

回答

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

+0

我会尝试这个和评论。谢谢 – nnopazo

相关问题