// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Windows.Forms; namespace DefaultNamespace { public class MainForm : Form { public static void Main() { try { MainForm fMainForm = new MainForm(); fMainForm.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } public MainForm() { InitializeComponent(); } private void InitializeComponent() { OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Databases\MSAccess\Test.mdb;"); con.Open(); OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM dtest", con); DataSet ds = new DataSet(); da.Fill(ds, "dtest"); DataGrid dg = new DataGrid(); SuspendLayout(); dg.Location = new Point(50, 50); dg.Size = new Size(300, 200); DataGridTextBoxColumn icol = new DataGridTextBoxColumn(); icol.MappingName = "i"; icol.Format = "0000"; DataGridTextBoxColumn dcol = new DataGridTextBoxColumn(); dcol.MappingName = "d"; dcol.Format = "HH:mm:ss"; DataGridTableStyle dgts = new DataGridTableStyle(); dgts.MappingName = "dtest"; dgts.GridColumnStyles.Add(icol); dgts.GridColumnStyles.Add(dcol); dg.TableStyles.Add(dgts); dg.SetDataBinding(ds, "dtest"); ClientSize = new Size(400, 400); Controls.Add(dg); Text = "Main Form"; ResumeLayout(false); } } }