3 Answers. Show activity on this post. var source = new BindingSource(); List<MyStruct> list = new List<MyStruct> { new MyStruct("fff", "b"), new MyStruct("c","d") }; source. DataSource = list; grid.
Step 1: Make a database with a table in SQL Server. Step 2: Create a Windows Application and add DataGridView on the Form. Now add a DataGridView control to the form by selecting it from Toolbox and set properties according to your needs.
In this blog I am going to describe how to bind the data source with “DataGridView” when window load. Create a Window form application have a look at my previous blog - how to create window form application. Once our window is ready click on Toolbox under “Data” choose “DataGridView” and drag onto the window.
I need to bind my DataTable to my DataGridView. i do this:
DTable = new DataTable(); SBind = new BindingSource(); //ServersTable - DataGridView for (int i = 0; i < ServersTable.ColumnCount; ++i) { DTable.Columns.Add(new DataColumn(ServersTable.Columns[i].Name)); } for (int i = 0; i < Apps.Count; ++i) { DataRow r = DTable.NewRow(); r.BeginEdit(); foreach (DataColumn c in DTable.Columns) { r[c.ColumnName] = //writing values } r.EndEdit(); DTable.Rows.Add(r); } SBind.DataSource = DTable; ServersTable.DataSource = SBind;
But all i got is DataTable ADDS NEW columns to my DataGridView. I don't need this, i just need to write under existing columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With