Rabin
Rabin

Reputation: 1583

Inserting rows into DataGridView using C#

I am currently developing a desktop application.

I have a DataTable filled up. How do I insert those data to the DataGridView?

Upvotes: 1

Views: 477

Answers (2)

Jude Cooray
Jude Cooray

Reputation: 19872

DataGridView.DataSource = yourDataTable;

If it is by any chance an ASP .NET Appication, don't forget to add

DataGridView.DataBind();

Upvotes: 1

painotpi
painotpi

Reputation: 6996

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.

Upvotes: 1

Related Questions