近來項目用到了一個類似WEB控件DataGrid中自定義行或列的顏色的功能
我們需要的則是標記某一行的數據
URL: ?id=
Public Class DataGridColoredTextBoxColumn
Inherits DataGridTextBoxColumn
Public rowcollection As New Collection()
Public BackColor() As Color
Public ForeColor() As Color
Private Function GetText(ByVal Value As Object) As String
If TypeOf (Value) Is System
Return NullText
ElseIf Value Is Nothing Then
Return
Else
Return Value
End If
End Function
Protected Overloads Overrides Sub Paint(ByVal g As System
ByVal source As System
ByVal rowNum As Integer
ByVal backBrush As System
ByVal foreBrush As System
ByVal alignToRight As Boolean)
Dim text As String
text = GetText(GetColumnValueAtRow(source
backBrush = New SolidBrush(TextBox
foreBrush = New SolidBrush(TextBox
ReDim Preserve BackColor(rowcollection
ReDim Preserve ForeColor(rowcollection
Dim i As Integer =
Do While (i <= rowcollection
If rowNum = Val(rowcollection
If Not BackColor(i
backBrush = New SolidBrush(BackColor(i
End If
If Not ForeColor(i
foreBrush = New SolidBrush(ForeColor(i
End If
End If
i +=
Loop
MyBase
End Sub
End Class
Imports System
Namespace Truck_WEB
Public Class DrawDGClass
Public Class ReDrawDataDridControls : Inherits DataGridColoredTextBoxColumn
Public Sub DrawCorol(ByRef DG As DataGrid
Dim dt As DataTable
Dim ts As New DataGridTableStyle()
ts
Dim aColumnTextColumn As DataGridColoredTextBoxColumn
dt = CType(DG
ts
DG
Dim numCols As Integer
numCols = dt
Dim i
i =
j =
Do While (i < numCols)
aColumnTextColumn = New DataGridColoredTextBoxColumn()
Dim rowindex As Integer =
For rowindex =
Dim StrSel As String
Dim MyForeCorol
aColumnTextColumn
If rowindex = CurrentRowindex Then
MyForeCorol = Color
MyBackCorol = Color
else
MyForeCorol = Color
MyBackCorol = Color
End If
ReDim Preserve aColumnTextColumn
ReDim Preserve aColumnTextColumn
aColumnTextColumn
aColumnTextColumn
Next
aColumnTextColumn
aColumnTextColumn
ts
i = (i +
Loop
DG
End Sub
End Class
End Class
End Namespace
以上是設定選中單行的顏色為反色
在此向《Henry手記:WinForm Datagrid結構剖析》的作者韓睿致謝!
以後我會盡量完善這個DrawDG的類
From:http://tw.wingwit.com/Article/program/net/201311/12321.html