Imports System.ComponentModel
Public Class myDataGridTextBoxColumn
Inherits System.Windows.Forms.DataGridTextBoxColumn
Private typeConverter As New typeConverter
Private Const yMargin = 1
Protected Overrides Sub Abort(ByVal rowNum As Integer)
MyBase.Abort(rowNum)
End Sub
Protected Overrides Function Commit(ByVal dataSource As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
Return MyBase.Commit(dataSource, rowNum)
End Function
Protected Overloads Overrides Sub Edit(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, _
ByVal bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, _
ByVal instantText As String, ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, [readOnly], instantText, cellIsVisible)
End Sub
Protected Overrides Function GetMinimumHeight() As Integer
Return MyBase.GetMinimumHeight
End Function
Protected Overrides Function GetPreferredHeight(ByVal g As System.Drawing.Graphics, ByVal value As Object) As Integer
Return MyBase.GetPreferredHeight(g, value)
End Function
Protected Overrides Function GetPreferredSize(ByVal g As System.Drawing.Graphics, ByVal value As Object) As System.Drawing.Size
Return MyBase.GetPreferredSize(g, value)
End Function
Private Function GetText(ByVal value As Object) As String
If TypeOf value Is DBNull Then
Return Me.NullText
End If
If (((Not Me.Format Is Nothing) AndAlso (Me.Format.Length <> 0)) AndAlso TypeOf value Is IFormattable) Then
Try
Return CType(value, IFormattable).ToString(Me.Format, Me.FormatInfo)
Catch exception1 As Exception
GoTo Label_0084
End Try
End If
If ((Not Me.typeConverter Is Nothing) AndAlso Me.typeConverter.CanConvertTo(GetType(String))) Then
Return CType(Me.typeConverter.ConvertTo(value, GetType(String)), String)
End If
Label_0084:
If (value Is Nothing) Then
Return ""
End If
Return value.ToString
End Function
Protected Sub PaintTxt(ByVal g As Graphics, ByVal Bounds As Rectangle, ByVal [text] As String, _
ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean _
, ByVal rowNum As Long)
Me.DataGridTableStyle.BackColor = System.Drawing.Color.Beige
Dim rect As RectangleF
rect.X = Bounds.X
rect.Y = Bounds.Y
rect.Height = Bounds.Height
rect.Width = Bounds.Width
Dim format1 As New StringFormat
If alignToRight Then
format1.FormatFlags = (format1.FormatFlags Or StringFormatFlags.DirectionRightToLeft)
End If
g.FillRectangle(backBrush, rect)
rect.Offset(0, (2 * Me.yMargin))
rect.Height = (rect.Height - (2 * Me.yMargin))
If rowNum Mod 3 <> 0 Then
g.DrawString(text, Me.DataGridTableStyle.DataGrid.Font, foreBrush, rect, format1)
Else
Dim fnt As New Font(Me.DataGridTableStyle.DataGrid.Font, FontStyle.Bold)
g.DrawString(text, fnt, foreBrush, rect, format1)
End If
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 text1 As String = Me.GetText(Me.GetColumnValueAtRow(source, rowNum))
Me.PaintTxt(g, bounds, text1, alignToRight, rowNum)
End Sub
Protected Sub PaintTxt(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal [text] As String, _
ByVal alignToRight As Boolean, ByVal Rownum As Long)
Dim forebrush As System.Drawing.Brush = System.Drawing.Brushes.Black
Dim Backbrush As System.Drawing.Brush = System.Drawing.Brushes.White
Me.PaintTxt(g, bounds, text, Backbrush, forebrush, alignToRight, Rownum)
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)
Me.Paint(g, bounds, source, rowNum, False)
End Sub
End Class