'Created By Database Hub, Inc.
'
'Date - 2004-12-07
'
'Email - mike@databasehub.com
'
'The Original Document Was Published At: 
'      http://www.dotnet247.com/247reference/a.aspx?u=http://www.codeproject.com/csharp/PracticalGuideDataGrids1.asp
'
'Note To Reader - This is a learning project. It was created so I could learn how to 
'work with the DataGrid, DataSet and DataTable Objects With A SQLite3 Database And CoreLab MySQLite.NET 
'There May Be Better Ways Of Performing These Tasks; What Is Presented Here Is A Proof Of Concept
'For My Personal Use.
'mike@databasehub.com
'
Imports System.Data
Imports DataGrid_DataSet_DataTable.KDNGrid
Imports DataGrid_DataSet_DataTable.ExceptionHandler


Public Class frmDataGrid
    Inherits System.Windows.Forms.Form
    Dim DTbl As DataTable 'Module Level
    Private WithEvents CMgr As CurrencyManager

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents cmdSizeCols As System.Windows.Forms.Button
    Friend WithEvents cmdEdit As System.Windows.Forms.Button
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents cmdCurrencyMangr1 As System.Windows.Forms.Button
    Friend WithEvents cmdCurrencyMangr As System.Windows.Forms.Button
    Friend WithEvents cmdAttachTable1 As System.Windows.Forms.Button
    Friend WithEvents CmdSave As System.Windows.Forms.Button
    Friend WithEvents CmdCancel As System.Windows.Forms.Button
    Friend WithEvents cmdLast As System.Windows.Forms.Button
    Friend WithEvents cmdNext As System.Windows.Forms.Button
    Friend WithEvents cmdPrev As System.Windows.Forms.Button
    Friend WithEvents cmdFirst As System.Windows.Forms.Button
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents chkMultiLineText As System.Windows.Forms.CheckBox
    Friend WithEvents lblValue As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents lblCellClicked As System.Windows.Forms.Label
    Friend WithEvents lblRowClicked As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents cboILECs As System.Windows.Forms.ComboBox
    Friend WithEvents cmdDeleteRow As System.Windows.Forms.Button
    Friend WithEvents cmdDataGridDocs As System.Windows.Forms.Button
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents cmdLoadDGrid1 As System.Windows.Forms.Button
    Friend WithEvents cmdLoadDGrid As System.Windows.Forms.Button
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents cmdCreateDB As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmDataGrid))
        Me.cmdSizeCols = New System.Windows.Forms.Button
        Me.cmdEdit = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.cmdCreateDB = New System.Windows.Forms.Button
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.cmdLoadDGrid1 = New System.Windows.Forms.Button
        Me.cmdLoadDGrid = New System.Windows.Forms.Button
        Me.cmdCurrencyMangr1 = New System.Windows.Forms.Button
        Me.cmdCurrencyMangr = New System.Windows.Forms.Button
        Me.cmdAttachTable1 = New System.Windows.Forms.Button
        Me.CmdSave = New System.Windows.Forms.Button
        Me.CmdCancel = New System.Windows.Forms.Button
        Me.cmdLast = New System.Windows.Forms.Button
        Me.cmdNext = New System.Windows.Forms.Button
        Me.cmdPrev = New System.Windows.Forms.Button
        Me.cmdFirst = New System.Windows.Forms.Button
        Me.cmdDataGridDocs = New System.Windows.Forms.Button
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.chkMultiLineText = New System.Windows.Forms.CheckBox
        Me.lblValue = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.lblCellClicked = New System.Windows.Forms.Label
        Me.lblRowClicked = New System.Windows.Forms.Label
        Me.cboILECs = New System.Windows.Forms.ComboBox
        Me.Label10 = New System.Windows.Forms.Label
        Me.cmdDeleteRow = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'cmdSizeCols
        '
        Me.cmdSizeCols.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdSizeCols.Location = New System.Drawing.Point(630, 180)
        Me.cmdSizeCols.Name = "cmdSizeCols"
        Me.cmdSizeCols.Size = New System.Drawing.Size(84, 20)
        Me.cmdSizeCols.TabIndex = 51
        Me.cmdSizeCols.Text = "Size Columns"
        '
        'cmdEdit
        '
        Me.cmdEdit.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdEdit.Location = New System.Drawing.Point(356, 448)
        Me.cmdEdit.Name = "cmdEdit"
        Me.cmdEdit.Size = New System.Drawing.Size(116, 20)
        Me.cmdEdit.TabIndex = 50
        Me.cmdEdit.Text = "Edit Selected Cell"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.GroupBox3)
        Me.GroupBox1.Controls.Add(Me.GroupBox2)
        Me.GroupBox1.Controls.Add(Me.cmdCurrencyMangr1)
        Me.GroupBox1.Controls.Add(Me.cmdCurrencyMangr)
        Me.GroupBox1.Controls.Add(Me.cmdAttachTable1)
        Me.GroupBox1.Location = New System.Drawing.Point(124, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(576, 128)
        Me.GroupBox1.TabIndex = 48
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Data Grids - Single Table"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.cmdCreateDB)
        Me.GroupBox3.Location = New System.Drawing.Point(12, 48)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(388, 72)
        Me.GroupBox3.TabIndex = 69
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "SQLite"
        '
        'cmdCreateDB
        '
        Me.cmdCreateDB.Location = New System.Drawing.Point(8, 16)
        Me.cmdCreateDB.Name = "cmdCreateDB"
        Me.cmdCreateDB.Size = New System.Drawing.Size(100, 20)
        Me.cmdCreateDB.TabIndex = 66
        Me.cmdCreateDB.Text = "Create DB"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.cmdLoadDGrid1)
        Me.GroupBox2.Controls.Add(Me.cmdLoadDGrid)
        Me.GroupBox2.Location = New System.Drawing.Point(408, 16)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(164, 104)
        Me.GroupBox2.TabIndex = 68
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Full Handlers"
        '
        'cmdLoadDGrid1
        '
        Me.cmdLoadDGrid1.Location = New System.Drawing.Point(16, 44)
        Me.cmdLoadDGrid1.Name = "cmdLoadDGrid1"
        Me.cmdLoadDGrid1.Size = New System.Drawing.Size(124, 20)
        Me.cmdLoadDGrid1.TabIndex = 70
        Me.cmdLoadDGrid1.Text = "Load Data View"
        '
        'cmdLoadDGrid
        '
        Me.cmdLoadDGrid.Location = New System.Drawing.Point(16, 20)
        Me.cmdLoadDGrid.Name = "cmdLoadDGrid"
        Me.cmdLoadDGrid.Size = New System.Drawing.Size(124, 20)
        Me.cmdLoadDGrid.TabIndex = 68
        Me.cmdLoadDGrid.Text = "Load Data Table"
        '
        'cmdCurrencyMangr1
        '
        Me.cmdCurrencyMangr1.Location = New System.Drawing.Point(276, 20)
        Me.cmdCurrencyMangr1.Name = "cmdCurrencyMangr1"
        Me.cmdCurrencyMangr1.Size = New System.Drawing.Size(124, 20)
        Me.cmdCurrencyMangr1.TabIndex = 36
        Me.cmdCurrencyMangr1.Text = "Currency Manager 1"
        '
        'cmdCurrencyMangr
        '
        Me.cmdCurrencyMangr.Location = New System.Drawing.Point(140, 20)
        Me.cmdCurrencyMangr.Name = "cmdCurrencyMangr"
        Me.cmdCurrencyMangr.Size = New System.Drawing.Size(124, 20)
        Me.cmdCurrencyMangr.TabIndex = 34
        Me.cmdCurrencyMangr.Text = "Currency Manager"
        '
        'cmdAttachTable1
        '
        Me.cmdAttachTable1.Location = New System.Drawing.Point(12, 20)
        Me.cmdAttachTable1.Name = "cmdAttachTable1"
        Me.cmdAttachTable1.Size = New System.Drawing.Size(116, 20)
        Me.cmdAttachTable1.TabIndex = 32
        Me.cmdAttachTable1.Text = "Attach Data Table"
        '
        'CmdSave
        '
        Me.CmdSave.Location = New System.Drawing.Point(516, 448)
        Me.CmdSave.Name = "CmdSave"
        Me.CmdSave.Size = New System.Drawing.Size(116, 20)
        Me.CmdSave.TabIndex = 46
        Me.CmdSave.Text = "Accept Edits"
        '
        'CmdCancel
        '
        Me.CmdCancel.Location = New System.Drawing.Point(204, 448)
        Me.CmdCancel.Name = "CmdCancel"
        Me.CmdCancel.Size = New System.Drawing.Size(116, 20)
        Me.CmdCancel.TabIndex = 45
        Me.CmdCancel.Text = "Undo Edits"
        '
        'cmdLast
        '
        Me.cmdLast.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdLast.Location = New System.Drawing.Point(666, 408)
        Me.cmdLast.Name = "cmdLast"
        Me.cmdLast.Size = New System.Drawing.Size(48, 16)
        Me.cmdLast.TabIndex = 44
        Me.cmdLast.Text = ">>"
        '
        'cmdNext
        '
        Me.cmdNext.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdNext.Location = New System.Drawing.Point(426, 408)
        Me.cmdNext.Name = "cmdNext"
        Me.cmdNext.Size = New System.Drawing.Size(48, 16)
        Me.cmdNext.TabIndex = 43
        Me.cmdNext.Text = ">"
        '
        'cmdPrev
        '
        Me.cmdPrev.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPrev.Location = New System.Drawing.Point(358, 408)
        Me.cmdPrev.Name = "cmdPrev"
        Me.cmdPrev.Size = New System.Drawing.Size(48, 16)
        Me.cmdPrev.TabIndex = 42
        Me.cmdPrev.Text = "<"
        '
        'cmdFirst
        '
        Me.cmdFirst.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdFirst.Location = New System.Drawing.Point(118, 408)
        Me.cmdFirst.Name = "cmdFirst"
        Me.cmdFirst.Size = New System.Drawing.Size(48, 16)
        Me.cmdFirst.TabIndex = 41
        Me.cmdFirst.Text = "<<"
        '
        'cmdDataGridDocs
        '
        Me.cmdDataGridDocs.Location = New System.Drawing.Point(708, 24)
        Me.cmdDataGridDocs.Name = "cmdDataGridDocs"
        Me.cmdDataGridDocs.Size = New System.Drawing.Size(92, 20)
        Me.cmdDataGridDocs.TabIndex = 40
        Me.cmdDataGridDocs.Text = "Data Grid Docs"
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(118, 200)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(596, 204)
        Me.DataGrid1.TabIndex = 39
        '
        'chkMultiLineText
        '
        Me.chkMultiLineText.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.chkMultiLineText.Location = New System.Drawing.Point(120, 164)
        Me.chkMultiLineText.Name = "chkMultiLineText"
        Me.chkMultiLineText.Size = New System.Drawing.Size(96, 32)
        Me.chkMultiLineText.TabIndex = 56
        Me.chkMultiLineText.Text = "Use MultiLine Text Column"
        '
        'lblValue
        '
        Me.lblValue.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblValue.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblValue.Location = New System.Drawing.Point(552, 160)
        Me.lblValue.Name = "lblValue"
        Me.lblValue.Size = New System.Drawing.Size(160, 19)
        Me.lblValue.TabIndex = 60
        Me.lblValue.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label4
        '
        Me.Label4.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(512, 164)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(33, 16)
        Me.Label4.TabIndex = 59
        Me.Label4.Text = "Value"
        '
        'Label5
        '
        Me.Label5.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(352, 164)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(64, 16)
        Me.Label5.TabIndex = 57
        Me.Label5.Text = "Cell Clicked"
        '
        'Label7
        '
        Me.Label7.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.Label7.AutoSize = True
        Me.Label7.Location = New System.Drawing.Point(224, 164)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(67, 16)
        Me.Label7.TabIndex = 61
        Me.Label7.Text = "Row Clicked"
        '
        'lblCellClicked
        '
        Me.lblCellClicked.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblCellClicked.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblCellClicked.Location = New System.Drawing.Point(424, 160)
        Me.lblCellClicked.Name = "lblCellClicked"
        Me.lblCellClicked.Size = New System.Drawing.Size(83, 20)
        Me.lblCellClicked.TabIndex = 58
        Me.lblCellClicked.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblRowClicked
        '
        Me.lblRowClicked.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblRowClicked.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblRowClicked.Location = New System.Drawing.Point(296, 160)
        Me.lblRowClicked.Name = "lblRowClicked"
        Me.lblRowClicked.Size = New System.Drawing.Size(40, 20)
        Me.lblRowClicked.TabIndex = 62
        Me.lblRowClicked.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'cboILECs
        '
        Me.cboILECs.Location = New System.Drawing.Point(4, 152)
        Me.cboILECs.Name = "cboILECs"
        Me.cboILECs.Size = New System.Drawing.Size(104, 21)
        Me.cboILECs.TabIndex = 63
        '
        'Label10
        '
        Me.Label10.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.Label10.AutoSize = True
        Me.Label10.Location = New System.Drawing.Point(8, 136)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(64, 16)
        Me.Label10.TabIndex = 64
        Me.Label10.Text = "ilecID~ILEC"
        '
        'cmdDeleteRow
        '
        Me.cmdDeleteRow.Location = New System.Drawing.Point(720, 180)
        Me.cmdDeleteRow.Name = "cmdDeleteRow"
        Me.cmdDeleteRow.Size = New System.Drawing.Size(100, 20)
        Me.cmdDeleteRow.TabIndex = 65
        Me.cmdDeleteRow.Text = "Delete Row"
        '
        'frmDataGrid
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(836, 481)
        Me.Controls.Add(Me.cmdDeleteRow)
        Me.Controls.Add(Me.Label10)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.cboILECs)
        Me.Controls.Add(Me.lblValue)
        Me.Controls.Add(Me.lblCellClicked)
        Me.Controls.Add(Me.lblRowClicked)
        Me.Controls.Add(Me.chkMultiLineText)
        Me.Controls.Add(Me.cmdSizeCols)
        Me.Controls.Add(Me.cmdEdit)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.CmdSave)
        Me.Controls.Add(Me.CmdCancel)
        Me.Controls.Add(Me.cmdLast)
        Me.Controls.Add(Me.cmdNext)
        Me.Controls.Add(Me.cmdPrev)
        Me.Controls.Add(Me.cmdFirst)
        Me.Controls.Add(Me.cmdDataGridDocs)
        Me.Controls.Add(Me.DataGrid1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmDataGrid"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "VB.NET DataTables, DataSets, DataGrids And SQLite3"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub DataGrid1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim myGrid As DataGrid = CType(sender, DataGrid)
        Dim hti As System.Windows.Forms.DataGrid.HitTestInfo
        hti = myGrid.HitTest(e.X, e.Y)
        Dim message As String = "You clicked "

        Select Case hti.Type
            Case System.Windows.Forms.DataGrid.HitTestType.None
                message &= "the background."
            Case System.Windows.Forms.DataGrid.HitTestType.Cell
                message &= "cell at row " & hti.Row & ", col " & hti.Column
            Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
                message &= "the column header for column " & hti.Column
            Case System.Windows.Forms.DataGrid.HitTestType.RowHeader
                message &= "the row header for row " & hti.Row
            Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
                message &= "the column resizer for column " & hti.Column
            Case System.Windows.Forms.DataGrid.HitTestType.RowResize
                message &= "the row resizer for row " & hti.Row
            Case System.Windows.Forms.DataGrid.HitTestType.Caption
                message &= "the caption"
            Case System.Windows.Forms.DataGrid.HitTestType.ParentRows
                message &= "the parent row"
        End Select

        Console.WriteLine(message)
    End Sub


    Private Sub EditGrid()
        'Private Sub EditGrid(ByVal myGrid As DataGrid)
        ' Get the selected row and column through the CurrentCell.
        Dim colNum As Integer
        Dim rowNum As Integer
        colNum = DataGrid1.CurrentCell.ColumnNumber
        rowNum = DataGrid1.CurrentCell.RowNumber
        ' Get the selected DataGridColumnStyle.
        Dim dgCol As DataGridColumnStyle
        dgCol = DataGrid1.TableStyles(0).GridColumnStyles(colNum)
        ' Invoke the BeginEdit method to see if editing can begin.
        If DataGrid1.BeginEdit(dgCol, rowNum) Then
            ' Edit row value. Get the DataTable and selected row.
            Dim myTable As DataTable
            Dim myRow As DataRow
            ' Assuming the DataGrid is bound to a DataTable.
            myTable = CType(DataGrid1.DataSource, DataTable)
            myRow = myTable.Rows(rowNum)
            ' Invoke the Row object's BeginEdit method.
            myRow.BeginEdit()
            If Object.ReferenceEquals(myRow.Item(colNum).GetType(), System.Type.GetType("System.String")) Then
                myRow(colNum) = "New Value"
            Else
                myRow(colNum) = 9
            End If
            ' Accept changes on both DataRow and DataTable.
            'myRow.AcceptChanges()
            'myTable.AcceptChanges()
            DataGrid1.EndEdit(dgCol, rowNum, False)

        Else
                Console.WriteLine("BeginEdit failed")
            End If
    End Sub 'EditGrid

    'Use Existing Table Style And Set Data Grid Column Widths
    'Found On MSDE.BIZ   Article Name - "Automatically Resizing DataGrid Columns"
    Public Shared Function DataGridApplyAutomaticWidths(ByVal DataGrid As System.Windows.Forms.DataGrid, ByVal TableStyle As DataGridTableStyle, _
    ByVal NumberOfRowsToScan As Integer, ByVal MaxPixelWidth As Integer) _
    As DataGridTableStyle
        'Create graphics object for measuring widths.
        Dim Graphics As Graphics = DataGrid.CreateGraphics()
        Try
            'If Object.ReferenceEquals(DataGrid.DataSource.GetType(), System.Type.GetType("System.Data.DataTable")) Then
            If DataGrid.DataSource.GetType().Name = "DataTable" Then
                Dim DataTable As DataTable
                'DataTable = DataGrid.DataSource.DataSet.Tables(0)
                DataTable = DataGrid.DataSource 'Use This If Bound To Data Table
                'DataTable = DataGrid.DataSource.Tables(0)
                'Can only scan rows if they exist.
                NumberOfRowsToScan = System.Math.Min(NumberOfRowsToScan, DataTable.Rows.Count)
                'Now loop through the columns and set the widths.
                Dim Column As DataColumn
                Dim ColumnStyle As DataGridColumnStyle
                Dim Width As Integer
                For Each Column In DataTable.Columns
                    ColumnStyle = TableStyle.GridColumnStyles(Column.ColumnName)
                    If Not ColumnStyle Is Nothing Then
                        'Set width to header text width.
                        Width = Graphics.MeasureString(ColumnStyle.HeaderText, DataGrid.Font, MaxPixelWidth).Width
                        'Change width, if data width is wider than header text width.
                        'Check the width of the data in the first X rows.
                        Dim iRow As Integer
                        Dim dr As DataRow
                        For iRow = 0 To NumberOfRowsToScan - 1
                            dr = DataTable.Rows(iRow)
                            If Not IsDBNull(dr(Column.ColumnName)) Then
                                Width = System.Math.Max(Width, Graphics.MeasureString(dr(Column.ColumnName), DataGrid.Font, MaxPixelWidth).Width)
                            End If
                        Next
                        ColumnStyle.Width = Width + 4
                    End If
                Next
            ElseIf DataGrid.DataSource.GetType().Name = "DataView" Then
                Dim DVw As DataView
                'DataTable = DataGrid.DataSource.DataSet.Tables(0)
                DVw = DataGrid.DataSource 'Use This If Bound To Data Table
                'DataTable = DataGrid.DataSource.Tables(0)
                'Can only scan rows if they exist.
                NumberOfRowsToScan = System.Math.Min(NumberOfRowsToScan, DVw.Table.Rows.Count)
                'Now loop through the columns and set the widths.
                Dim Column As DataColumn
                Dim ColumnStyle As DataGridColumnStyle
                Dim Width As Integer
                For Each Column In DVw.Table.Columns
                    ColumnStyle = TableStyle.GridColumnStyles(Column.ColumnName)
                    If Not ColumnStyle Is Nothing Then
                        'Set width to header text width.
                        Width = Graphics.MeasureString(ColumnStyle.HeaderText, DataGrid.Font, MaxPixelWidth).Width
                        'Change width, if data width is wider than header text width.
                        'Check the width of the data in the first X rows.
                        Dim iRow As Integer
                        Dim dr As DataRow
                        For iRow = 0 To NumberOfRowsToScan - 1
                            dr = DVw.Table.Rows(iRow)
                            If Not IsDBNull(dr(Column.ColumnName)) Then
                                Width = System.Math.Max(Width, Graphics.MeasureString(dr(Column.ColumnName), DataGrid.Font, MaxPixelWidth).Width)
                            End If
                        Next
                        ColumnStyle.Width = Width + 4
                    End If
                Next
            End If

        Finally
            Graphics.Dispose()
        End Try

        Return TableStyle
    End Function

    Public Shared Function DataGridApplyAutomaticWidthsAndTableStyle(ByVal DataGrid As System.Windows.Forms.DataGrid, ByVal NumberOfRowsToScan As Integer, ByVal MaxPixelWidth As Integer) _
    As DataGridTableStyle
        'Create graphics object for measuring widths.
        Dim Graphics As Graphics = DataGrid.CreateGraphics()
        'Define new table style.
        Dim TableStyle As DataGridTableStyle = New DataGridTableStyle
        Try
            Dim DataTable As DataTable
            'DataTable = DataGrid.DataSource.DataSet.Tables(0) 
            'DataTable = DataGrid.DataSource.Tables(0)
            DataTable = DataGrid.DataSource
            'Can only scan rows if they exist.
            NumberOfRowsToScan = System.Math.Min(NumberOfRowsToScan, DataTable.Rows.Count)
            'Clear any existing table styles.
            DataGrid.TableStyles.Clear()
            'Use mapping name that is defined in the data source.
            TableStyle.MappingName = DataTable.TableName
            'Now create the column styles within the table style.
            Dim Column As DataColumn
            Dim ColumnStyle As DataGridTextBoxColumn
            Dim Width As Integer
            For Each Column In DataTable.Columns
                ColumnStyle = New DataGridTextBoxColumn
                With ColumnStyle
                    .TextBox.Enabled = True
                    .HeaderText = Column.ColumnName
                    .MappingName = Column.ColumnName
                    'Set width to header text width.
                    Width = Graphics.MeasureString(.HeaderText, DataGrid.Font, MaxPixelWidth).Width
                End With
                'Change width, if data width is wider than header text width.
                'Check the width of the data in the first X rows.
                Dim iRow As Integer
                Dim DataRow As DataRow
                For iRow = 0 To NumberOfRowsToScan - 1
                    DataRow = DataTable.Rows(iRow)
                    If Not IsDBNull(DataRow(Column.ColumnName)) Then
                        Width = System.Math.Max(Width, Graphics.MeasureString(DataRow(Column.ColumnName), DataGrid.Font, MaxPixelWidth).Width)
                    End If
                Next
                ColumnStyle.Width = Width + 4
                'Add the new column style to the table style.
                TableStyle.GridColumnStyles.Add(ColumnStyle)
            Next
            'Add the new table style to the data grid.
            DataGrid.TableStyles.Add(TableStyle)
        Finally
            Graphics.Dispose()
        End Try
        Return TableStyle
    End Function


    Private Sub AttachTableStyle1()
        'Editable - Sortable Grid
        Dim DCol As DataColumn

        'Create a TableStyle For The DataGrid
        Dim TStyle As New DataGridTableStyle
        Dim TxtCol As DataGridTextBoxColumn

        For Each DCol In DTbl.Columns
            TxtCol = New DataGridTextBoxColumn
            TxtCol.MappingName = DCol.ColumnName
            TxtCol.HeaderText = DCol.Caption
            If DCol.DataType Is System.Type.GetType("System.String") Then
                TxtCol.Width = 170
            Else
                TxtCol.Width = 40
            End If
            TxtCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
            TxtCol.ReadOnly = True
            TStyle.GridColumnStyles.Add(TxtCol)
        Next

        TStyle.MappingName = DTbl.TableName
        'TStyle.AllowSorting = False
        'TStyle.ReadOnly = True

        'Clear Any Existing Table Styles
        DataGrid1.TableStyles.Clear()

        DataGrid1.TableStyles.Add(TStyle)

        DataGrid1.DataSource = DTbl

    End Sub

    Private Sub AttachTableStyle2()
        'Non Editable - Non Sortable Grid
        Dim DCol As DataColumn

        'Create a TableStyle For The DataGrid
        Dim TStyle As New DataGridTableStyle
        Dim TxtCol As DataGridTextBoxColumn

        For Each DCol In DTbl.Columns
            TxtCol = New DataGridTextBoxColumn
            TxtCol.MappingName = DCol.ColumnName
            TxtCol.HeaderText = DCol.Caption
            If DCol.DataType Is System.Type.GetType("System.String") Then
                TxtCol.Width = 170
            Else
                TxtCol.Width = 40
            End If
            TxtCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
            TxtCol.ReadOnly = True
            TStyle.GridColumnStyles.Add(TxtCol)
        Next

        TStyle.MappingName = DTbl.TableName
        TStyle.AllowSorting = False
        TStyle.ReadOnly = True

        'Clear Any Existing Table Styles
        DataGrid1.TableStyles.Clear()

        DataGrid1.TableStyles.Add(TStyle)

        DataGrid1.DataSource = DTbl

    End Sub

    Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Cancel Changes
        CMgr.CancelCurrentEdit()
    End Sub

    Private Sub CMgr_CurrentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CMgr.CurrentChanged
        'MessageBox.Show("CurrencyManager CurrentChanged Event Fired")
        'DataGrid1.BeginEdit()
    End Sub

    Private Sub CMgr_ItemChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemChangedEventArgs) Handles CMgr.ItemChanged
        'MessageBox.Show("CurrencyManager ItemChanged Event Fired")

    End Sub

    Private Sub CMgr_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CMgr.PositionChanged
        If CMgr.Position = CMgr.Count - 1 Then
            cmdNext.Enabled = False
            cmdLast.Enabled = False
        Else
            cmdNext.Enabled = True
            cmdLast.Enabled = True
        End If

        If CMgr.Position = 0 Then
            cmdPrev.Enabled = False
            cmdFirst.Enabled = False
        Else
            cmdPrev.Enabled = True
            cmdFirst.Enabled = True
        End If

        lblRowClicked.Text = CMgr.Position

        'lblRow.Text = "Row " & CType(Me.BindingContext(DTbl), CurrencyManager).Position
    End Sub

    Private Sub cmdCurrencyMangr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCurrencyMangr.Click
        DTbl = CreateTableMemoryObjectNoPK()
        AddDataToDTableFromSQL(DTbl)

        CMgr = CType(Me.BindingContext(DTbl), CurrencyManager)

        'Clear any existing TableStyles
        CGrid.ClearTableStyles(DataGrid1)

        AttachTableStyle2() 'Now Detects Row Change Events In Grid

    End Sub

    Private Sub cmdAttachTable1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAttachTable1.Click
        'Clear any existing TableStyles
        CGrid.ClearTableStyles(DataGrid1)

        DTbl = CreateTableMemoryObjectNoPK()
        AddDataToDTableFromSQL(DTbl)

        AttachTableStyle2()
        DataGrid1.ResetBindings()
        'AttachNoPKSingleTable()

    End Sub

    Private Sub cmdCurrencyMangr1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCurrencyMangr1.Click
        DTbl = CreateTableMemoryObjectNoPK()
        AddDataToDTableFromSQL(DTbl)

        CMgr = CType(Me.BindingContext(DTbl), CurrencyManager)

        'Clear any existing TableStyles
        CGrid.ClearTableStyles(DataGrid1)


        AttachTableStyle1() 'Now Detects Row Change Events In Grid


    End Sub

    Private Sub cmdLast_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLast.Click
        'Move To Last Row
        CMgr.Position = CMgr.Count

    End Sub

    Private Sub cmdNext_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
        'Forward One Row
        CMgr.Position += 1

    End Sub

    Private Sub cmdPrev_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrev.Click
        'Back One Row
        CMgr.Position -= 1

    End Sub

    Private Sub cmdFirst_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFirst.Click
        'Move To First Row
        CMgr.Position = 0

    End Sub

    Private Sub CmdCancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCancel.Click
        DTbl.RejectChanges()
    End Sub

    Private Sub cmdEdit_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEdit.Click
        EditGrid()
    End Sub

    Private Sub CmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSave.Click
        'Read Through DataTable - Determine Row States And Make Appropriate SQLite Table Changes
        'Changes Affected Table Whether DTbl or BVw Was Used By Grid
        Dim DRow As DataRow

        For Each DRow In DTbl.Rows
            Select Case DRow.RowState
                Case 4 'Added - AcceptChanges Has Not Been Called.
                    'TO DO - Test Values - Pass This Data And Insert Into Database
                    MsgBox("Added - AcceptChanges Has Not Been Called.")
                Case 8 'Deleted Using Delete Method
                    'TO DO - Pass This ID and Delete From Database
                    MsgBox("Deleted Using Delete Method")
                Case 1 'Created But Not Added  or  It Has Been Removed
                    'TO DO - Nothing    
                    MsgBox("Created But Not Added  or  It Has Been Removed")
                Case 16 'Modified - AcceptChanges Has Not Been Called.
                    MsgBox("Modified - AcceptChanges Has Not Been Called.")
                    If DRow.HasVersion(DataRowVersion.Proposed) Then
                        If DRow(1, DataRowVersion.Current) Is DRow(1, DataRowVersion.Proposed) Then
                            'MessageBox.Show("The Original And The Proposed Are The Same")
                            DRow.CancelEdit()
                            Exit Sub
                        Else
                            'TO DO - Test Values - Pass This Data and Update Database
                            DRow.AcceptChanges()
                        End If
                    End If
                Case 2 'Not Changed 
                    'TO DO - Nothing
            End Select
        Next
    End Sub

    Private Sub cmdSizeCols_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSizeCols.Click
        Dim MyDataGrid1 As DataGrid = DataGrid1
        Dim TStyle As DataGridTableStyle = DataGrid1.TableStyles(0)
        Dim NbrRows As Integer = DTbl.Rows.Count
        Dim MaxPixels As Integer = 200
        DataGridApplyAutomaticWidths(MyDataGrid1, TStyle, NbrRows, MaxPixels)

    End Sub

    Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
        'This code will handle changing the value of the CheckBox column in 
        'column1 on a single click, rather than having to click once to activate,
        'then again to change the value.  It also will select the entire row
        'when column1 is clicked.

        Dim ClickedRowIndex As Integer
        Dim bChecked As Boolean
        Dim ClickedColumnName As String
        Dim result As Object = Nothing
        Dim DGrd As DataGrid = DataGrid1

        If DGrd.DataSource.GetType().Name = "DataTable" Then

            'Determine what was clicked
            ClickedRowIndex = CGrid.GetClickedCellAndRow(CType(DataGrid1.DataSource, DataTable), Me.DataGrid1, ClickedColumnName, result, False)

            If ClickedRowIndex > -1 AndAlso ClickedColumnName.ToUpper = "ID" Then
                'Column1 was clicked - Toggle the value and select the row
                ClickedRowIndex = CGrid.SelectCheckBoxRow(CType(DataGrid1.DataSource, DataTable), Me.DataGrid1, e, "ID", bChecked, 0, True)
                result = bChecked
            End If

            If ClickedRowIndex > -1 Then
                'Update the UI
                Me.lblCellClicked.Text = ClickedColumnName
                Me.lblRowClicked.Text = ClickedRowIndex.ToString
                If Not result Is Nothing Then
                    Me.lblValue.Text = result.ToString
                End If
            End If
        ElseIf DGrd.DataSource.GetType().Name = "DataView" Then
            'Determine what was clicked
            ClickedRowIndex = CGrid.GetClickedCellAndRow(CType(DataGrid1.DataSource, DataView), Me.DataGrid1, ClickedColumnName, result, False)

            If ClickedRowIndex > -1 AndAlso ClickedColumnName.ToUpper = "ID" Then
                'Column1 was clicked - Toggle the value and select the row
                ClickedRowIndex = CGrid.SelectCheckBoxRow(CType(DataGrid1.DataSource, DataView), Me.DataGrid1, e, "ID", bChecked, 0, True)
                result = bChecked
            End If

            If ClickedRowIndex > -1 Then
                'Update the UI
                Me.lblCellClicked.Text = ClickedColumnName
                Me.lblRowClicked.Text = ClickedRowIndex.ToString
                If Not result Is Nothing Then
                    Me.lblValue.Text = result.ToString
                End If
            End If

        End If

    End Sub

    Private Shared Sub DTbl_OnColumnChanged(ByVal sender As Object, ByVal args As DataColumnChangeEventArgs)
        Console.Write(" ColumnChanged: ")
        Console.Write(args.Column.ColumnName & " changed to '" & args.ProposedValue.ToString() & "'" & vbCrLf)
    End Sub

    Private Shared Sub DTbl_OnRowChanged(ByVal sender As Object, ByVal args As DataRowChangeEventArgs)
        If args.Action <> DataRowAction.Nothing Then
            Dim actionStr As String
            actionStr = System.Enum.GetName(args.Action.GetType(), args.Action)

            Console.WriteLine("    RowChanged: Action = " & actionStr & ", CustID = " & args.Row("CustID").ToString())
        End If
    End Sub

    Private Sub cmdDataGridDocs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDataGridDocs.Click
        Try
            System.Diagnostics.Process.Start("DataGridDocs.htm")
        Catch
            HandledExceptionManager.ShowDialog("An Unexpected Error Occurred Displaying The Data Grid Docs!", _
                "The Documentation Cannot Be Displayed.", _
                "Please Contact Tech Support", _
                "Tech Support Phone Numbers", _
                HandledExceptionManager.EHBtn.OK, _
                HandledExceptionManager.EHIcon.Stp, _
                0)
        Finally
            'No Finally Needed
        End Try

    End Sub


    Private Sub cmdCreateDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCreateDB.Click
        CreateDatabaseHub()

    End Sub

    Private Sub frmDataGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddForm()
        frmDataGridRef = Me
    End Sub

    Private Sub frmDataGrid_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed
        SubForm()
        frmDataGridRef = Nothing

    End Sub

    Private Shared Sub DVw_OnListChanged(ByVal sender As Object, ByVal args As System.ComponentModel.ListChangedEventArgs)
        Console.WriteLine("ListChanged:")
        Console.WriteLine(vbTab & "    Type = " & System.Enum.GetName(args.ListChangedType.GetType(), args.ListChangedType))
        Console.WriteLine(vbTab & "OldIndex = " & args.OldIndex)
        Console.WriteLine(vbTab & "NewIndex = " & args.NewIndex)
    End Sub

    Private Sub cmdLoadDGrid_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadDGrid.Click
        'Binding To The Data Table Allows Records To Be Added 

        'Create BillTasks Table Object
        DTbl = CreateTableMemoryObjectNoPK()

        'Populate Table With Data
        AddDataToDTableFromSQL(DTbl)

        'Will Start At First Record - Disable Controls
        cmdPrev.Enabled = False
        cmdFirst.Enabled = False

        'Attach CurrencyManager To Data Table
        CMgr = CType(Me.BindingContext(DTbl), CurrencyManager)

        'Add Event Handlers To Detect Data Changes
        AddHandler DTbl.ColumnChanged, New DataColumnChangeEventHandler(AddressOf DTbl_OnColumnChanged)

        AddHandler DTbl.RowChanged, New DataRowChangeEventHandler(AddressOf DTbl_OnRowChanged)

        'Clear any existing TableStyles
        CGrid.ClearTableStyles(DataGrid1)

        'Create a TableStyle to contain the ColumnStyles for the grid.
        '(An alternate method for doing this is at the end of this method)
        Dim TStyle As DataGridTableStyle = CGrid.GetTableStyle(DTbl)

        'ID Column Is Not Editable - 
        'TextBox Column - ReadOnly
        Dim cs1 As New CGridTextBoxStyle("ID", 10, _
                                         HorizontalAlignment.Left, True, _
                                         "ID", "", "")
        CGrid.AddColumn(TStyle, cs1)

        'clecID Column Is Not Editable - 
        'TextBox Column - ReadOnly
        Dim cs2 As New CGridTextBoxStyle("clecID", 10, _
                                         HorizontalAlignment.Left, True, _
                                         "clecID", "", "")
        CGrid.AddColumn(TStyle, cs2)

        'ComboBox Column
        'Get ILECs From SQLite
        Dim ILECs() As String ' = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}
        GetILECs(ILECs)
        Dim i As Integer
        'Split ILECs Contents and Populate Combo
        For i = 0 To ILECs.GetUpperBound(0)
            cboILECs.Items.Add(ILECs(i))
            If IsNumeric(ILECs(i).Chars(1)) = True Then
                ILECs(i) = ILECs(i).Remove(2, ILECs(i).Length - 2)
            Else
                ILECs(i) = ILECs(i).Remove(1, ILECs(i).Length - 1)
            End If
        Next
        Dim cs3 As New CGridComboBoxStyle("ilecID", 20, _
                                          HorizontalAlignment.Left, _
                                          "ilecID", "(null)", _
                                          ILECs, ComboBoxStyle.DropDownList)
        CGrid.AddColumn(TStyle, cs3)


        'ComboBox Column
        'Resale is 0 or 1
        Dim Items1() As String = {"0", "1"}
        Dim cs4 As New CGridComboBoxStyle("Resale", 20, _
                                          HorizontalAlignment.Left, _
                                          "Resale", "(null)", _
                                          Items1, ComboBoxStyle.DropDownList)
        CGrid.AddColumn(TStyle, cs4)

        'ComboBox Column
        'UNEP is 0 or 1
        Dim Items2() As String = {"0", "1"}
        Dim cs5 As New CGridComboBoxStyle("UNEP", 20, _
                                          HorizontalAlignment.Left, _
                                          "UNEP", "(null)", _
                                          Items2, ComboBoxStyle.DropDownList)
        CGrid.AddColumn(TStyle, cs5)

        'NumericUpDown Column
        Dim cs6 As New CGridNumericUpDownStyle("TaskOrder", 60, "TaskOrder", 0, 6, _
                                               0, 1, LeftRightAlignment.Right, _
                                               0, "#,##0")
        CGrid.AddColumn(TStyle, cs6)

        'TextBox Column
        Dim cs7 As New CGridTextBoxStyle("Task", 100, _
                                         HorizontalAlignment.Left, True, _
                                         "Task", "", "")
        CGrid.AddColumn(TStyle, cs7)

        'TextBox Column
        Dim cs8 As New CGridTextBoxStyle("Descr", 100, _
                                         HorizontalAlignment.Left, True, _
                                         "Descr", "", "")
        CGrid.AddColumn(TStyle, cs8)


        'Set an AlternatingBackColor - just for looks
        TStyle.AlternatingBackColor = Color.LightGoldenrodYellow

        'Set the TableStyle for the Grid
        CGrid.SetGridStyle(Me.DataGrid1, DTbl, TStyle)

        'Uncomment this line to prevent the user from adding rows to the grid
        'CGrid.DisableAddNew(DataGrid1, Me)

        'Turn off the title bar for the grid
        'Me.DataGrid1.CaptionVisible = False

        'Size The Columns
        DataGridApplyAutomaticWidths(DataGrid1, TStyle, DTbl.Rows.Count, 200)



    End Sub

    Private Sub cmdLoadDGrid1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadDGrid1.Click
        'Binding To A Data View Does Not Allows Records To Be Added 

        'Create BillTasks Table Object
        DTbl = CreateTableMemoryObjectNoPK()

        'Populate Table With Data
        AddDataToDTableFromSQL(DTbl)

        'Create A View Of The Table 
        Dim DVw As DataView = New DataView(DTbl, _
                                      "", _
                                      "ID", _
                                      DataViewRowState.CurrentRows)
        DVw.AllowNew = False 'Stops New Rows From Being Added

        'Will Start At First Record - Disable Controls
        cmdPrev.Enabled = False
        cmdFirst.Enabled = False

        'Attach CurrencyManager To Data Table
        CMgr = CType(Me.BindingContext(DVw), CurrencyManager)

        AddHandler DVw.ListChanged, New System.ComponentModel.ListChangedEventHandler(AddressOf DVw_OnListChanged)

        'Clear any existing TableStyles
        CGrid.ClearTableStyles(DataGrid1)

        'Create a TableStyle to contain the ColumnStyles for the grid.
        '(An alternate method for doing this is at the end of this method)
        Dim TStyle As DataGridTableStyle = CGrid.GetTableStyle(DVw)

        'ID Column Is Not Editable - 
        'TextBox Column - ReadOnly
        Dim cs1 As New CGridTextBoxStyle("ID", 10, _
                                         HorizontalAlignment.Left, True, _
                                         "ID", "", "")
        CGrid.AddColumn(TStyle, cs1)

        'clecID Column Is Not Editable - 
        'TextBox Column - ReadOnly
        Dim cs2 As New CGridTextBoxStyle("clecID", 10, _
                                         HorizontalAlignment.Left, True, _
                                         "clecID", "", "")
        CGrid.AddColumn(TStyle, cs2)

        'ComboBox Column
        'Get ILECs From SQLite
        Dim ILECs() As String
        GetILECs(ILECs)
        Dim i As Integer
        'Split ILECs Contents and Populate Combo
        For i = 0 To ILECs.GetUpperBound(0)
            cboILECs.Items.Add(ILECs(i))
            If IsNumeric(ILECs(i).Chars(1)) = True Then
                ILECs(i) = ILECs(i).Remove(2, ILECs(i).Length - 2)
            Else
                ILECs(i) = ILECs(i).Remove(1, ILECs(i).Length - 1)
            End If
        Next
        Dim cs3 As New CGridComboBoxStyle("ilecID", 20, _
                                          HorizontalAlignment.Left, _
                                          "ilecID", "(null)", _
                                          ILECs, ComboBoxStyle.DropDownList)
        CGrid.AddColumn(TStyle, cs3)


        'ComboBox Column
        'Resale is 0 or 1
        Dim Items1() As String = {"0", "1"}
        Dim cs4 As New CGridComboBoxStyle("Resale", 20, _
                                          HorizontalAlignment.Left, _
                                          "Resale", "(null)", _
                                          Items1, ComboBoxStyle.DropDownList)
        CGrid.AddColumn(TStyle, cs4)

        'ComboBox Column
        'UNEP is 0 or 1
        Dim Items2() As String = {"0", "1"}
        Dim cs5 As New CGridComboBoxStyle("UNEP", 20, _
                                          HorizontalAlignment.Left, _
                                          "UNEP", "(null)", _
                                          Items2, ComboBoxStyle.DropDownList)
        CGrid.AddColumn(TStyle, cs5)

        'NumericUpDown Column
        Dim cs6 As New CGridNumericUpDownStyle("TaskOrder", 60, "TaskOrder", 0, 6, _
                                               0, 1, LeftRightAlignment.Right, _
                                               0, "#,##0")
        CGrid.AddColumn(TStyle, cs6)

        'TextBox Column
        Dim cs7 As New CGridTextBoxStyle("Task", 100, _
                                         HorizontalAlignment.Left, True, _
                                         "Task", "", "")
        CGrid.AddColumn(TStyle, cs7)

        'TextBox Column
        Dim cs8 As New CGridTextBoxStyle("Descr", 100, _
                                         HorizontalAlignment.Left, True, _
                                         "Descr", "", "")
        CGrid.AddColumn(TStyle, cs8)


        'Set an AlternatingBackColor - just for looks
        TStyle.AlternatingBackColor = Color.LightGoldenrodYellow

        'Set the TableStyle for the Grid
        CGrid.SetGridStyle(Me.DataGrid1, DVw, TStyle)

        'Uncomment this line to prevent the user from adding rows to the grid
        'CGrid.DisableAddNew(DataGrid1, Me)

        'Turn off the title bar for the grid
        'Me.DataGrid1.CaptionVisible = False

        'Size The Columns
        DataGridApplyAutomaticWidths(DataGrid1, TStyle, DVw.Table.Rows.Count, 200)

    End Sub

    Private Sub cmdDeleteRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDeleteRow.Click
        MsgBox("Not Implemented")
    End Sub
End Class
