主题:datagrid 的行如何按条件变颜色
[font=宋体][/font]
与datagrid---这里是DG绑定的数据表中一字段满足要求则该单元格能改变颜色
可是按以下程序未实现,请教!
‘主程序中调用xianshi()
Private Sub xianshi()
Dim TC_jl As New coloredtextboxcolumn
TC_jl.MappingName = "hy_jl"
TC_jl.HeaderText = "结论"
TS_hyhl.GridColumnStyles.Add(TC_jl)
DG.TableStyles.Add(TS_hyhl)
end sub
Public Class coloredtextboxcolumn
Inherits DataGridTextBoxColumn
Protected Friend Overridable Overloads Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, _
ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim Objval As Object
Objval = Me.GetColumnValueAtRow(source, rowNum)
If Not (IsNothing(Objval) Or IsDBNull(Objval)) Then
Dim cellValue As String
cellValue = CType(Objval, String)
If cellValue <>"正常" Then
foreBrush = Brushes.Red
backBrush = Brushes.Black
Else
backBrush = Brushes.Red
foreBrush = Brushes.Blue
End If
End If
MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)
End Sub
End Class
与datagrid---这里是DG绑定的数据表中一字段满足要求则该单元格能改变颜色
可是按以下程序未实现,请教!
‘主程序中调用xianshi()
Private Sub xianshi()
Dim TC_jl As New coloredtextboxcolumn
TC_jl.MappingName = "hy_jl"
TC_jl.HeaderText = "结论"
TS_hyhl.GridColumnStyles.Add(TC_jl)
DG.TableStyles.Add(TS_hyhl)
end sub
Public Class coloredtextboxcolumn
Inherits DataGridTextBoxColumn
Protected Friend Overridable Overloads Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, _
ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim Objval As Object
Objval = Me.GetColumnValueAtRow(source, rowNum)
If Not (IsNothing(Objval) Or IsDBNull(Objval)) Then
Dim cellValue As String
cellValue = CType(Objval, String)
If cellValue <>"正常" Then
foreBrush = Brushes.Red
backBrush = Brushes.Black
Else
backBrush = Brushes.Red
foreBrush = Brushes.Blue
End If
End If
MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)
End Sub
End Class