Inserting rows into DataGridView using C#
I am currentl开发者_如何学Goy developing a desktop application.
I have a DataTable filled up. How do I insert those data to the DataGridView?
try this,
//the DataGridView
DataGridView myDataGriView = new DataGridView();
//Declare BindingSource to sync DataGridView and data table
BindingSource myBindingSource = new BindingSource();
//set the DataSource property of your BindingSource
myBindingSource.DataSource = myDataTable;
//set the DataSource property of your DataGridView
myDataGridView.DataSource = myBindingSource;
Hope it helped,
If you want more information of populating your dataTable with data from a database you can check this tutorial.
DataGridView.DataSource = yourDataTable;
If it is by any chance an ASP .NET Appication, don't forget to add
DataGridView.DataBind();
精彩评论