Imports System.Data.OleDb
Imports System.IO

Public Class Form1
    Inherits System.Windows.Forms.Form

#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 checkBox3 As System.Windows.Forms.CheckBox
    Friend WithEvents checkBox2 As System.Windows.Forms.CheckBox
    Friend WithEvents checkBox1 As System.Windows.Forms.CheckBox
    Friend WithEvents dataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents dataGrid2 As System.Windows.Forms.DataGrid
    Friend WithEvents DataGrid3 As System.Windows.Forms.DataGrid
    Friend WithEvents C1ExpressConnection1 As C1.Data.Express.C1ExpressConnection
    Friend WithEvents C1ExpressTable1 As C1.Data.Express.C1ExpressTable
    Friend WithEvents C1ExpressTable2 As C1.Data.Express.C1ExpressTable
    Friend WithEvents C1ExpressView1 As C1.Data.Express.C1ExpressView
    Friend WithEvents C1ExpressView2 As C1.Data.Express.C1ExpressView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.checkBox3 = New System.Windows.Forms.CheckBox
        Me.checkBox2 = New System.Windows.Forms.CheckBox
        Me.checkBox1 = New System.Windows.Forms.CheckBox
        Me.dataGrid1 = New System.Windows.Forms.DataGrid
        Me.dataGrid2 = New System.Windows.Forms.DataGrid
        Me.C1ExpressConnection1 = New C1.Data.Express.C1ExpressConnection
        Me.DataGrid3 = New System.Windows.Forms.DataGrid
        Me.C1ExpressTable1 = New C1.Data.Express.C1ExpressTable
        Me.C1ExpressTable2 = New C1.Data.Express.C1ExpressTable
        Me.C1ExpressView1 = New C1.Data.Express.C1ExpressView
        Me.C1ExpressView2 = New C1.Data.Express.C1ExpressView
        CType(Me.dataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.dataGrid2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1ExpressConnection1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataGrid3, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1ExpressTable1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1ExpressTable2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1ExpressView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1ExpressView2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'checkBox3
        '
        Me.checkBox3.Location = New System.Drawing.Point(544, 502)
        Me.checkBox3.Name = "checkBox3"
        Me.checkBox3.Size = New System.Drawing.Size(160, 16)
        Me.checkBox3.TabIndex = 12
        Me.checkBox3.Text = "Custom list of rows"
        '
        'checkBox2
        '
        Me.checkBox2.Location = New System.Drawing.Point(376, 502)
        Me.checkBox2.Name = "checkBox2"
        Me.checkBox2.Size = New System.Drawing.Size(120, 16)
        Me.checkBox2.TabIndex = 11
        Me.checkBox2.Text = "EmployeeID = 1"
        '
        'checkBox1
        '
        Me.checkBox1.Location = New System.Drawing.Point(200, 502)
        Me.checkBox1.Name = "checkBox1"
        Me.checkBox1.Size = New System.Drawing.Size(128, 16)
        Me.checkBox1.TabIndex = 10
        Me.checkBox1.Text = "City = 'London'"
        '
        'dataGrid1
        '
        Me.dataGrid1.DataMember = ""
        Me.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dataGrid1.Location = New System.Drawing.Point(8, 22)
        Me.dataGrid1.Name = "dataGrid1"
        Me.dataGrid1.Size = New System.Drawing.Size(888, 216)
        Me.dataGrid1.TabIndex = 8
        '
        'dataGrid2
        '
        Me.dataGrid2.DataMember = "_Customers.Customers - Orders"
        Me.dataGrid2.DataSource = Me.C1ExpressConnection1
        Me.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dataGrid2.Location = New System.Drawing.Point(24, 240)
        Me.dataGrid2.Name = "dataGrid2"
        Me.dataGrid2.Size = New System.Drawing.Size(864, 248)
        Me.dataGrid2.TabIndex = 14
        '
        'C1ExpressConnection1
        '
        Me.C1ExpressConnection1.BindingContextCtrl = Me
        Me.C1ExpressConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\ComponentOne Studio" & _
            ".NET 2.0\common\Nwind.mdb;Persist Security Info=False"
        Me.C1ExpressConnection1.DummyImage = CType(resources.GetObject("C1ExpressConnection1.DummyImage"), System.Drawing.Bitmap)
        Me.C1ExpressConnection1.Locale = New System.Globalization.CultureInfo("en-US")
        Me.C1ExpressConnection1.SerializedRelations = resources.GetString("C1ExpressConnection1.SerializedRelations")
        Me.C1ExpressConnection1.SerializedSchemaXML = Me.C1ExpressConnection1.GetSchemaFromResources(resources, "C1ExpressConnection1", Me)
        '
        'DataGrid3
        '
        Me.DataGrid3.DataMember = "_Customers"
        Me.DataGrid3.DataSource = Me.C1ExpressConnection1
        Me.DataGrid3.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid3.Location = New System.Drawing.Point(24, 16)
        Me.DataGrid3.Name = "DataGrid3"
        Me.DataGrid3.Size = New System.Drawing.Size(872, 216)
        Me.DataGrid3.TabIndex = 13
        '
        'C1ExpressTable1
        '
        Me.C1ExpressTable1.BindingContextCtrl = Me
        Me.C1ExpressTable1.ConnectionComponent = Me.C1ExpressConnection1
        Me.C1ExpressTable1.ConnectionString = ""
        Me.C1ExpressTable1.DummyImage = CType(resources.GetObject("C1ExpressTable1.DummyImage"), System.Drawing.Bitmap)
        Me.C1ExpressTable1.FullComponentName = "Form1.C1ExpressTable1"
        Me.C1ExpressTable1.SchemaTableName = "Customers"
        Me.C1ExpressTable1.TableViewName = "Customers"
        Me.C1ExpressTable1.SerializedSchemaXML = Me.C1ExpressTable1.GetSchemaFromResources(resources, "C1ExpressTable1", Me)
        '
        'C1ExpressTable2
        '
        Me.C1ExpressTable2.BindingContextCtrl = Me
        Me.C1ExpressTable2.ConnectionComponent = Me.C1ExpressConnection1
        Me.C1ExpressTable2.ConnectionString = ""
        Me.C1ExpressTable2.DummyImage = CType(resources.GetObject("C1ExpressTable2.DummyImage"), System.Drawing.Bitmap)
        Me.C1ExpressTable2.FullComponentName = "Form1.C1ExpressTable2"
        Me.C1ExpressTable2.SchemaTableName = "Orders"
        Me.C1ExpressTable2.TableViewName = "Orders"
        Me.C1ExpressTable2.SerializedSchemaXML = Me.C1ExpressTable2.GetSchemaFromResources(resources, "C1ExpressTable2", Me)
        '
        'C1ExpressView1
        '
        Me.C1ExpressView1.BindingContextCtrl = Me
        Me.C1ExpressView1.ExpressTableComponent = Me.C1ExpressTable1
        Me.C1ExpressView1.ExpressTableName = "C1ExpressTable1"
        Me.C1ExpressView1.FullTableName = "Form1.C1ExpressTable1"
        Me.C1ExpressView1.IsDefault = True
        '
        'C1ExpressView2
        '
        Me.C1ExpressView2.BindingContextCtrl = Me
        Me.C1ExpressView2.ExpressTableComponent = Me.C1ExpressTable2
        Me.C1ExpressView2.ExpressTableName = "C1ExpressTable2"
        Me.C1ExpressView2.FullTableName = "Form1.C1ExpressTable2"
        Me.C1ExpressView2.IsDefault = True
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(904, 541)
        Me.Controls.Add(Me.dataGrid2)
        Me.Controls.Add(Me.DataGrid3)
        Me.Controls.Add(Me.checkBox3)
        Me.Controls.Add(Me.checkBox2)
        Me.Controls.Add(Me.checkBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.dataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.dataGrid2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1ExpressConnection1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataGrid3, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1ExpressTable1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1ExpressTable2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1ExpressView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1ExpressView2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub checkBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkBox1.CheckedChanged
        If checkBox1.Checked Then
            C1ExpressView1.RowFilter = "City = 'London'"
        Else
            C1ExpressView1.RowFilter = ""
        End If
    End Sub

    Private Sub checkBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkBox2.CheckedChanged
        If checkBox2.Checked Then
            C1ExpressView2.RowFilter = "EmployeeID = 1"
        Else
            C1ExpressView2.RowFilter = ""
        End If
    End Sub

    Private Sub checkBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkBox3.CheckedChanged
        _customListOfRows = checkBox3.Checked
        If _customListOfRows Then
            C1ExpressView1.RowFilter = ""
        End If
        C1ExpressView1.Refresh()
    End Sub

    Private _customListOfRows As Boolean
    Private Sub C1ExpressView1_GetRows(ByVal sender As Object, ByVal e As C1.Data.GetListEventArgs) Handles C1ExpressView1.GetRows
        If Not _customListOfRows Then Exit Sub
        Dim list As ArrayList = New ArrayList()
        Dim row As C1.Data.C1DataRow
        For Each row In e.List
            If row("ContactTitle").ToString() = "Sales Agent" Then
                list.Add(row)
            End If
        Next
        e.List = list
    End Sub

#Region " Switch to C1NWind.mdb database "

    Private Sub C1ExpressConnection1_BeforeFill(ByVal sender As System.Object, ByVal e As C1.Data.FillEventArgs) Handles C1ExpressConnection1.BeforeFill
        If Not C1ExpressConnection1.DataSet.Filled Then
            UpdateDbPath()
        End If
    End Sub

    Private Sub UpdateDbPath()
        Dim dbPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + _
            "\ComponentOne Samples\Common\C1NWind.mdb"
        If File.Exists(dbPath) Then
            Dim csb As New OleDbConnectionStringBuilder(C1ExpressConnection1.ConnectionString)
            csb.DataSource = dbPath
            C1ExpressConnection1.ConnectionString = csb.ToString()
        End If
    End Sub

#End Region

End Class
