如何根据datagrid里面某个字段的值,来定义这行的颜色,
比如当DataGrid1.Row = 7
DataGrid1.Columns.Item(4).Text = 5 时
这行的颜色为红色

解决方案 »

  1.   

    DataGrid好像不好隔行设置颜色吧,可以选择用MSHFlexGrid,而且更好点。 
      

  2.   

    DataGrid好像不好隔行设置颜色,可以选择用MSHFlexGrid,而且更好点。我原来也是为了这个问题找了半天资料,最好还是选择MSHFlexGrid
      

  3.   

    是vb6.0,其他的程序都写好了,就剩下这个了,有没有办法啊?
    我在网上查资料,说可以用子类化,可是我看了半天,也没有搞定。
    http://hi.baidu.com/starwork/blog/ITem/c4a274a7bd944694d043584b.HTML
      

  4.   

    我使用的是True DBgrid 6.0元件,做法如下:
    grdDataGrid是控制項的名稱
    FetchCellStyle是控制項的方法Private Sub grdDataGrid_FetchCellStyle(ByVal Condition As Integer, ByVal Split As Integer, Book As Variant, ByVal Col As Integer, ByVal CellStyle As TrueDBGrid60.StyleDisp)
       With grdDataGrid
         If .Columns(Col).CellText(Book) = "5" Then
           CellStyle.BackColor = RGB(255, 255, 0)
         End If
         If .Columns(Col).CellText(Book) = "6" Then
           CellStyle.BackColor = RGB(0, 255, 255)
         End If
         If .Columns(Col).CellText(Book) = "7" Then
           CellStyle.BackColor = RGB(255, 0, 255)
         End If
       End With
    End Sub
    希望對你有幫助
      

  5.   

    我在对listview设置颜色时是用picture来画的
      

  6.   

    datagrid 没有这个方法阿,有没有其他的办法?   子类化应该怎么做啊?
    那位帮帮忙阿!
      

  7.   

    如果数据量不大,建议用listview,这个想咋设就咋设,请看我的回复
    http://topic.csdn.net/u/20090608/09/fd8b3f5a-59cb-40c5-8dac-484f29fdc2ec.html