📄 datagridtextboxcolumn.vb
字号:
Public Class DataGridTextBoxColumn
Inherits System.Windows.Forms.DataGridTextBoxColumn
Private m_IsRedIfOverDue As Boolean = False
Public Sub New(ByVal format As String, ByVal headerText As String, ByVal mappingName As String, ByVal width As Integer)
MyBase.Format = format
MyBase.HeaderText = headerText
MyBase.MappingName = mappingName
MyBase.Width = width
End Sub
Public Sub New(ByVal format As String, ByVal headerText As String, ByVal mappingName As String, ByVal width As Integer, ByVal isRedIfOverDue As Boolean)
MyBase.Format = format
MyBase.HeaderText = headerText
MyBase.MappingName = mappingName
MyBase.Width = width
m_IsRedIfOverDue = isRedIfOverDue
End Sub
Protected Overloads Overrides Sub Edit(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal isReadOnly As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
'Do Nothing
'This is a ReadOnly DataGrid
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 Integer, ByVal backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush, ByVal alignToRight As Boolean)
Dim bVal As Object = GetColumnValueAtRow(source, rowNum)
If Me.Format = "d" Then
Try
'globalize for german
If Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName = "de" Then
bVal = String.Format("{0:d}", Convert.ToDateTime(bVal).ToString("dd/MM/yy"))
Else
bVal = String.Format("{0:d}", Convert.ToDateTime(bVal))
End If
Catch
'ignore an invalid cast
End Try
End If
'if the current row is this row, draw the selection back color
If Me.DataGridTableStyle.DataGrid.CurrentRowIndex = rowNum Then
g.FillRectangle(New SolidBrush(Me.DataGridTableStyle.SelectionBackColor), bounds)
g.DrawString(CType(bVal, String), Me.DataGridTableStyle.DataGrid.Font, New SolidBrush(Me.DataGridTableStyle.SelectionForeColor), bounds.X + 2, bounds.Y + 2)
Else
g.FillRectangle(backBrush, bounds)
If m_IsRedIfOverDue Then
Try
If Convert.ToDateTime(bVal).Date < DateTime.Now.Date Then
g.DrawString(CType(bVal, String), Me.DataGridTableStyle.DataGrid.Font, New SolidBrush(Color.Red), bounds.X + 2, bounds.Y + 2)
Else
g.DrawString(CType(bVal, String), Me.DataGridTableStyle.DataGrid.Font, foreBrush, bounds.X + 2, bounds.Y + 2)
End If
Catch
g.DrawString(CType(bVal, String), Me.DataGridTableStyle.DataGrid.Font, foreBrush, bounds.X + 2, bounds.Y + 2)
End Try
Else
g.DrawString(CType(bVal, String), Me.DataGridTableStyle.DataGrid.Font, foreBrush, bounds.X + 2, bounds.Y + 2)
End If
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -