- DataTable products = new DataTable("Product List");
- DataColumn name = new DataColumn("Product Name");
- DataColumn price = new DataColumn("Product Price");
- products.Columns.Add(name);
- products.Columns.Add(price);
- DataRow product1 = products.NewRow();
- product1["Product Name"] = "180 Hard Drive";
- product1["Product Price"] = 39.00;
- DataRow product2 = products.NewRow();
- product2["Product Name"] = "MP3 Player";
- product2["Product Price"] = 29.99;
- DataRow product3 = products.NewRow();
- product3["Product Name"] = "128 Graphics Card";
- product3["Product Price"] = 49.99;
- products.Rows.Add(product1);
- products.Rows.Add(product2);
- products.Rows.Add(product3);
- DataGrid grid = new DataGrid();
- grid.Dock = DockStyle.Fill;
- grid.DataSource = products;
- this.Controls.Add(grid);
Simple DataGrid Example In C#
This snippet shows how to add rows to a DataGrid control using the DataRow class.
No comments:
Post a Comment