根据字段间比较获得指定单元的颜色的类(vb.net)

前几日,搜了好久有关vb.net中DataGrid指定行颜色设置的相关信息,拜读了很多力作。稍微修改了以下,用了以下还不错。

 

 

             Dim  arrList  As   New  ArrayList

            
For  i  As   Integer   =   0   To  mytable.Rows.Count  -   1
                
If   CInt (mytable.Rows(i)( " Bladder_Max " ))  >   CInt (mytable.Rows(i)( " Bladder_Count " ))  Then
                    arrList.Add(
0 )
                
Else
                    arrList.Add(
1 )
                
End   If
            
Next
            
Dim  TextCol  As  DataGridColoredTextBoxColumn

            TextCol 
=   New  DataGridColoredTextBoxColumn(arrList, mytable.Rows.Count, Color.White, Color.Red)
            TextCol.MappingName 
=   " Bladder_Name "
            TextCol.HeaderText 
=   " Bladder名称 "
            TextCol.Alignment 
=  System.Windows.Forms.HorizontalAlignment.Center
            TextCol.Width 
=   Me .DataGrid1.Width  /   6   -   10
            TextCol.TextBox.Enabled 
=   False
            ts1.GridColumnStyles.Add(TextCol)

           
' ........

            
Me .DataGrid1.TableStyles.Clear()
            
Me .DataGrid1.TableStyles.Add(ts1)

 

Public   Class DataGridColoredTextBoxColumntBoxColumn

    
Private m_Row As Integer = -1
    
Private m_BackColor As Color = Color.White
    
Private m_ForeColor As Color = Color.Black

    
Private defalutBack As Brush = New SolidBrush(Color.White)
    
Private defalutFore As Brush = New SolidBrush(Color.Black)

    
Private m_Smt As Integer
    
Private m_Array As ArrayList
    
Sub New(ByVal Row As IntegerByVal [ForeColor] As Color)
        m_Row 
= Row
        m_ForeColor 
= ForeColor
    
End Sub


    
Sub New(ByVal row As IntegerByVal [ForeColor] As Color, ByVal [BackColor] As Color)
        m_Row 
= row
        m_ForeColor 
= ForeColor
        m_BackColor 
= BackColor
    
End Sub

    
Sub New(ByVal row As IntegerByVal cnt As IntegerByVal [ForeColor] As Color, ByVal [BackColor] As Color)
        m_Row 
= row
        m_Smt 
= cnt
        m_ForeColor 
= ForeColor
        m_BackColor 
= BackColor
    
End Sub

    
Sub New(ByVal arrList As ArrayList, ByVal cnt As IntegerByVal [ForeColor] As Color, ByVal [BackColor] As Color)
        m_Row 
= -1
        m_Array 
= arrList
        m_Smt 
= cnt
        m_ForeColor 
= ForeColor
        m_BackColor 
= BackColor
    
End Sub


    
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As IntegerByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
        
Try
            
If rowNum < m_Smt Then
                
If m_Array(rowNum) = 0 Then
                
Else
                    backBrush 
= New SolidBrush(m_BackColor)
                    foreBrush 
= New SolidBrush(m_ForeColor)
                
End If
            
End If
        
Catch ex As Exception
            
' empty catch 
        Finally
            
MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)
        
End Try
    
End Sub

End Class

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值