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
    Friend WithEvents C1TrueDBGrid1 As C1.Win.C1TrueDBGrid.C1TrueDBGrid
    Friend WithEvents C1TrueDBGrid2 As C1.Win.C1TrueDBGrid.C1TrueDBGrid
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents C1SchemaDef1 As C1.Data.C1SchemaDef
    Friend WithEvents C1DataSet1 As C1.Data.C1DataSet
    Friend WithEvents C1DataSet2 As C1.Data.C1DataSet

    '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.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.C1TrueDBGrid1 = New C1.Win.C1TrueDBGrid.C1TrueDBGrid
        Me.C1DataSet1 = New C1.Data.C1DataSet
        Me.C1SchemaDef1 = New C1.Data.C1SchemaDef
        Me.C1TrueDBGrid2 = New C1.Win.C1TrueDBGrid.C1TrueDBGrid
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.C1DataSet2 = New C1.Data.C1DataSet
        CType(Me.C1TrueDBGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1DataSet1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1SchemaDef1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1TrueDBGrid2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.C1DataSet2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'C1TrueDBGrid1
        '
        Me.C1TrueDBGrid1.Caption = "Customers"
        Me.C1TrueDBGrid1.DataMember = "_CustOrders"
        Me.C1TrueDBGrid1.DataSource = Me.C1DataSet1
        Me.C1TrueDBGrid1.GroupByCaption = "Drag a column header here to group by that column"
        Me.C1TrueDBGrid1.Images.Add(CType(resources.GetObject("C1TrueDBGrid1.Images"), System.Drawing.Image))
        Me.C1TrueDBGrid1.Location = New System.Drawing.Point(0, 8)
        Me.C1TrueDBGrid1.Name = "C1TrueDBGrid1"
        Me.C1TrueDBGrid1.PreviewInfo.Location = New System.Drawing.Point(0, 0)
        Me.C1TrueDBGrid1.PreviewInfo.Size = New System.Drawing.Size(0, 0)
        Me.C1TrueDBGrid1.PreviewInfo.ZoomFactor = 75
        Me.C1TrueDBGrid1.PrintInfo.PageSettings = CType(resources.GetObject("C1TrueDBGrid1.PrintInfo.PageSettings"), System.Drawing.Printing.PageSettings)
        Me.C1TrueDBGrid1.Size = New System.Drawing.Size(504, 168)
        Me.C1TrueDBGrid1.TabIndex = 0
        Me.C1TrueDBGrid1.Text = "C1TrueDBGrid1"
        Me.C1TrueDBGrid1.PropBag = resources.GetString("C1TrueDBGrid1.PropBag")
        '
        'C1DataSet1
        '
        Me.C1DataSet1.DataLibrary = ""
        Me.C1DataSet1.DataLibraryUrl = ""
        Me.C1DataSet1.DataSetDef = "CustOrders"
        Me.C1DataSet1.Locale = New System.Globalization.CultureInfo("en-US")
        Me.C1DataSet1.Name = "C1DataSet1"
        Me.C1DataSet1.SchemaClassName = ""
        Me.C1DataSet1.SchemaDef = Me.C1SchemaDef1
        '
        'C1SchemaDef1
        '
        Me.C1SchemaDef1.DummyImage = CType(resources.GetObject("C1SchemaDef1.DummyImage"), System.Drawing.Bitmap)
        Me.C1SchemaDef1.SerializedSchemaXML = Me.C1SchemaDef1.GetSchemaFromResources(resources, "C1SchemaDef1", Me)
        Me.C1SchemaDef1.SerializedDesignTimeOptionsXML = Me.C1SchemaDef1.GetDesignTimeOptionsFromResources(resources, "C1SchemaDef1", Me)
        '
        'C1TrueDBGrid2
        '
        Me.C1TrueDBGrid2.Caption = "Orders"
        Me.C1TrueDBGrid2.DataMember = "_CustOrders.CO - ODP"
        Me.C1TrueDBGrid2.DataSource = Me.C1DataSet1
        Me.C1TrueDBGrid2.GroupByCaption = "Drag a column header here to group by that column"
        Me.C1TrueDBGrid2.Images.Add(CType(resources.GetObject("C1TrueDBGrid2.Images"), System.Drawing.Image))
        Me.C1TrueDBGrid2.Location = New System.Drawing.Point(0, 184)
        Me.C1TrueDBGrid2.Name = "C1TrueDBGrid2"
        Me.C1TrueDBGrid2.PreviewInfo.Location = New System.Drawing.Point(0, 0)
        Me.C1TrueDBGrid2.PreviewInfo.Size = New System.Drawing.Size(0, 0)
        Me.C1TrueDBGrid2.PreviewInfo.ZoomFactor = 75
        Me.C1TrueDBGrid2.PrintInfo.PageSettings = CType(resources.GetObject("C1TrueDBGrid2.PrintInfo.PageSettings"), System.Drawing.Printing.PageSettings)
        Me.C1TrueDBGrid2.Size = New System.Drawing.Size(504, 152)
        Me.C1TrueDBGrid2.TabIndex = 1
        Me.C1TrueDBGrid2.Text = "C1TrueDBGrid2"
        Me.C1TrueDBGrid2.PropBag = resources.GetString("C1TrueDBGrid2.PropBag")
        '
        'DataGrid1
        '
        Me.DataGrid1.CaptionText = "Employees"
        Me.DataGrid1.DataMember = "Employees"
        Me.DataGrid1.DataSource = Me.C1DataSet1
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(512, 8)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(368, 328)
        Me.DataGrid1.TabIndex = 2
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(304, 368)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(120, 32)
        Me.Button1.TabIndex = 3
        Me.Button1.Text = "Commit changes"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(456, 368)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(128, 32)
        Me.Button2.TabIndex = 4
        Me.Button2.Text = "Products and Orders"
        '
        'C1DataSet2
        '
        Me.C1DataSet2.DataLibrary = ""
        Me.C1DataSet2.DataLibraryUrl = ""
        Me.C1DataSet2.DataSetDef = "ProductsOrders"
        Me.C1DataSet2.Locale = New System.Globalization.CultureInfo("en-US")
        Me.C1DataSet2.Name = "C1DataSet2"
        Me.C1DataSet2.SchemaClassName = ""
        Me.C1DataSet2.SchemaDef = Me.C1SchemaDef1
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(888, 429)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.DataGrid1)
        Me.Controls.Add(Me.C1TrueDBGrid2)
        Me.Controls.Add(Me.C1TrueDBGrid1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.C1TrueDBGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1DataSet1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1SchemaDef1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1TrueDBGrid2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.C1DataSet2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        C1DataSet1.Update()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim form2 As Form2
        form2 = New Form2()
        form2.SetDataSet(C1DataSet2)
        form2.ShowDialog(Me)
    End Sub

    Private Sub C1DataSet2_BeforeFill(ByVal sender As Object, ByVal e As C1.Data.FillEventArgs) Handles C1DataSet2.BeforeFill
        Dim dataSetDef As C1.Data.SchemaObjects.DataSetDef
        dataSetDef = e.DataSet.Schema.DataSetDefs("ProductsOrders")
        e.Filter.Add(New C1.Data.FilterCondition(dataSetDef.TableViews("ProductsOrderDetailsCust"), "[CategoryID] = 1"))
        e.Filter.Add(New C1.Data.FilterCondition(dataSetDef.TableViews("CustOrdersDetails"), "[CategoryID] = 1"))
    End Sub

#Region " Switch to C1NWind.mdb database "

    Private Sub C1SchemaDef1_CreateSchema(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles C1SchemaDef1.CreateSchema
        Dim dbPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + _
            "\ComponentOne Samples\Common\C1NWind.mdb"
        If File.Exists(dbPath) Then
            Dim conn As C1.Data.SchemaObjects.Connection = C1SchemaDef1.Schema.Connections(0)
            Dim csb As New OleDbConnectionStringBuilder(conn.ConnectionString)
            csb.DataSource = dbPath
            conn.ConnectionString = csb.ToString()
        End If
    End Sub

#End Region

End Class
