根据字段间比较获得指定单元的颜色的类(vb.net)
来源:互联网 发布:泛微网络 编辑:程序博客网 时间:2024/06/06 00:19
前几日,搜了好久有关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)
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 DataGridColoredTextBoxColumntBoxColumnClass 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()Sub New(ByVal Row As Integer, ByVal [ForeColor] As Color)
m_Row = Row
m_ForeColor = ForeColor
End Sub
Sub New()Sub New(ByVal row As Integer, ByVal [ForeColor] As Color, ByVal [BackColor] As Color)
m_Row = row
m_ForeColor = ForeColor
m_BackColor = BackColor
End Sub
Sub New()Sub New(ByVal row As Integer, ByVal cnt As Integer, ByVal [ForeColor] As Color, ByVal [BackColor] As Color)
m_Row = row
m_Smt = cnt
m_ForeColor = ForeColor
m_BackColor = BackColor
End Sub
Sub New()Sub New(ByVal arrList As ArrayList, ByVal cnt As Integer, ByVal [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()Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal 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
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()Sub New(ByVal Row As Integer, ByVal [ForeColor] As Color)
m_Row = Row
m_ForeColor = ForeColor
End Sub
Sub New()Sub New(ByVal row As Integer, ByVal [ForeColor] As Color, ByVal [BackColor] As Color)
m_Row = row
m_ForeColor = ForeColor
m_BackColor = BackColor
End Sub
Sub New()Sub New(ByVal row As Integer, ByVal cnt As Integer, ByVal [ForeColor] As Color, ByVal [BackColor] As Color)
m_Row = row
m_Smt = cnt
m_ForeColor = ForeColor
m_BackColor = BackColor
End Sub
Sub New()Sub New(ByVal arrList As ArrayList, ByVal cnt As Integer, ByVal [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()Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal 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
- 根据字段间比较获得指定单元的颜色的类(vb.net)
- 修改数据窗口指定单元的颜色
- PHP数组根据数组内的某个单元字段排序
- PHP数组根据数组内的某个单元字段排序
- 根据指定条件获得窗口的函数
- 获得指定表的字段名
- VB.NET中根据DataGridView中显示的数据条件数据行显示不同的颜色
- vb.net与vb的比较
- vb和vb.net的比较
- Gridview绑定数据库的字段,根据条件字段颜色改变
- VB.NET根据年月获得总周数
- 比较经典的位字段例题(颜色三原色)
- [VB.NET]单元三 常用控件的使用
- vb.net获得dataset的内容
- Vb.Net 通过反射获取类的字段值
- vb.net设置单元格的颜色
- 文本读取指定行的类(vb.net)
- Oracle根据表名获得其主键的字段名
- VS2005中连接数据库“provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错”的一种情况
- 批处理命令用法简介
- PE 文件格式(二)
- PE文件格式(三)
- 使用MFC操作Excel,写入
- 根据字段间比较获得指定单元的颜色的类(vb.net)
- PE文件格式(四)
- 用C#访问Hotmail
- 16道嵌入式C语言面试题(经典)
- redhat EL5 安装
- Unix常用监控和管理命令
- 一个页面在运行时,如何在页面上显示“正在运行页面,请稍候”
- TD边框
- Sun Solaris 用户手册