using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;

namespace SchemaExtenderAndColumnStyles
{
    partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            textBox1.Text = c1DataViewSet1.Views[0].Definition;
            checkBox1.Checked = c1TrueDBGrid1.UseColumnStyles;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            c1TrueDBGrid1.ClearFields();
            c1DataViewSet1.Views[0].Definition = textBox1.Text;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            c1TrueDBGrid1.UseColumnStyles = checkBox1.Checked;
        }

        private void c1DataViewSet1_ConnectionOpening(object sender, C1.C1DataExtender.ConnectionOpeningEventArgs e)
        {
            OleDbConnectionStringBuilder csb = new OleDbConnectionStringBuilder(e.Connection.ConnectionString);
            /// If connection string specified in application resources points to a non-existant database file
            /// then use a database from a default sample database location.
            if (!File.Exists(csb.DataSource))
            {
                csb.DataSource = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                     @"ComponentOne Samples\Common\C1NWind.mdb");
                e.Connection.ConnectionString = csb.ToString();
            }
        }
    }
}