private void genericListExample_Click(object sender, EventArgs e) // Отображение обобщенных коллекций { var form = new DataGridViewExample(grid => { var people = new List <Person> { new Person("Fred", Sex.Male, new DateTime(1970, 12, 14)), new Person("Bill", Sex.Male, new DateTime(1976, 10, 29)), new Person("Jack", Sex.Male, new DateTime(1945, 5, 17)), new Person("Jane", Sex.Female, new DateTime(1982, 1, 3)) }; grid.AutoGenerateColumns = true; grid.DataSource = people; }) { MdiParent = this }; form.Show(); }
private void dataTableSourceExample_Click(object sender, EventArgs e) { DataGridViewExample form = new DataGridViewExample(grid => { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["northwind"].ConnectionString)) { string select = "SELECT * FROM products"; SqlDataAdapter da = new SqlDataAdapter(select, con); DataSet ds = new DataSet(); da.Fill(ds, "Products"); grid.AutoGenerateColumns = true; grid.DataSource = ds.Tables["Products"]; } }); form.MdiParent = this; form.Show(); }
private void dataSetExample_Click(object sender, EventArgs e) { DataGridViewExample form = new DataGridViewExample(grid => { string customers = "SELECT * FROM Customers"; using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["northwind"].ConnectionString)) { DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(customers, con); da.Fill(ds, "Customers"); grid.AutoGenerateColumns = true; grid.DataSource = ds; grid.DataMember = "Customers"; } }); form.MdiParent = this; form.Show(); }
private void dataSetExample_Click(object sender, EventArgs e) // Форма заполнения DataGridView для СУБД { var gridViewExample = new DataGridViewExample(grid => { const string customers = "SELECT * FROM Customers"; using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["northwind"].ConnectionString)) { var dataSource = new DataSet(); using (var sqlDataAdapter = new SqlDataAdapter(customers, con)) { sqlDataAdapter.Fill(dataSource, "Customers"); } grid.AutoGenerateColumns = true; grid.DataSource = dataSource; grid.DataMember = "Customers"; } }) { MdiParent = this }; gridViewExample.Show(); }
// Форма заполнения DataGridView для DataTable-источника данных private void dataTableSourceExample_Click(object sender, EventArgs e) { var form = new DataGridViewExample(grid => { using ( var northConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["northwind"].ConnectionString)) { const string productSelect = "SELECT * FROM products"; using (var dataAdapter = new SqlDataAdapter(productSelect, northConnection)) { var dataSet = new DataSet(); dataAdapter.Fill(dataSet, "Products"); grid.AutoGenerateColumns = true; grid.DataSource = dataSet.Tables["Products"]; } } }) { MdiParent = this }; form.Show(); }