'It succeeds and DataGrid control is created.
Public Class CustomDataGrid
    Inherits DataGrid
    Public headerLine As Boolean = False

    'The line displayed at the head of DataGrid is set up.
    Public Sub SetTopRow(ByVal rowNum As Integer)
        Dim args As New ScrollEventArgs( _
            ScrollEventType.LargeIncrement, rowNum)
        GridVScrolled(Me, args)
    End Sub

    Public Function GetTopRow() As Integer
        Return VertScrollBar.Value
    End Function

    'Sideways scrolling is set up.
    Public Sub HScrollSet(ByVal rowNum As Integer)
        Dim args As New ScrollEventArgs( _
                   ScrollEventType.LargeIncrement, rowNum)
        gridhscrolled(Me, args)
    End Sub
    'Horizontal scrolling of DataGrid is acquired.
    Public Function getHScroll() As ScrollBar
        Return HorizScrollBar
    End Function

    'When a tab key is pushed in the cell in DataGrid, a focus is moved to other control.
    Const WM_KEYDOWN As Integer = &H100
    Private mControl As Windows.Forms.Control = Me

    Public Property NextControl() As Control
            Return mControl
        End Get
        Set(ByVal Value As Control)
            mControl = Value
        End Set
    End Property

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
    ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If msg.Msg = WM_KEYDOWN Then
            If (keyData = Keys.Tab) Then
                Return (True)
                Return MyBase.ProcessCmdKey(msg, keyData)
            End If
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

    Private Sub CustomDataGrid_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        If (headerLine) Then
            Dim height As Integer = Me.Font.Height + 5
            Dim width As Integer = 0 - getHScroll().Value
            Dim i As Integer = 0

            For i = 0 To Me.Controls.Count - 3
                width += Me.TableStyles.Item(0).GridColumnStyles(i).Width
                e.Graphics.DrawLine(New System.Drawing.Pen(Me.TableStyles.Item(0).GridLineColor), _
               New System.Drawing.PointF(width - 1, 0), New System.Drawing.PointF(width - 1, height))
            Next i
            e.Graphics.DrawLine(New System.Drawing.Pen(Me.TableStyles.Item(0).GridLineColor), _
            New System.Drawing.PointF(0, height), New System.Drawing.PointF(width - 1, height))
        End If
    End Sub

    Private Sub CustomDataGrid_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Scroll
    End Sub

    Protected Overrides Sub OnMouseWheel(ByVal e As System.Windows.Forms.MouseEventArgs)
    End Sub
End Class

Public Class ColorDataGridTextBoxColumn
    Inherits DataGridTextBoxColumn
    Protected Overloads Overrides Sub Paint( _
            ByVal g As Graphics, _
            ByVal bounds As Rectangle, _
            ByVal source As CurrencyManager, _
            ByVal rowNum As Integer, _
            ByVal backBrush As Brush, _
            ByVal foreBrush As Brush, _
            ByVal alignToRight As Boolean _
        If Not (Me.DataGridTableStyle.DataGrid.CurrentCell.RowNumber = rowNum) Then

            foreBrush = New SolidBrush(Color.Black)
            backBrush = New SolidBrush(System.Windows.Forms.Form.DefaultBackColor)

        End If

        MyBase.Paint(g, bounds, source, rowNum, _
            backBrush, foreBrush, alignToRight)
    End Sub
End Class