Hi,
How to Create DataGridView Dynamically in C#.
Thanks, in advance
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Aug 25, 2011, 2:08 AM
Look at the samples in the MSDN.
Generate a Windows Forms application and put a DataGridView in the form. Then look at the Designer.cs file for the form; you will have a useful sample.
Priya LingePosted Aug 25, 2011, 1:07 AM
Follwing way we can create DataGridView dynamicaly,
string query = "select * from Customer";
sqlConnection.Open();
sqlCommand = new SqlCommand(query, sqlConnection);
da = new SqlDataAdapter(sqlCommand);
ds = new DataSet();
da.Fill(ds);
DataGridView myDataGrid = new DataGridView();
myDataGrid.DataSource = ds.Tables[0];
myDataGrid.Show();
panel1.Controls.Add(myDataGrid);
Hope this will help you.
Thanks.