Hi,
How to Create DataGridView Dynamically in C#.
Thanks, in advance
How to Create DataGridView Dynamically
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Priya LingeRank #785 · 2.9K reputationPosted Aug 24, 2011, 9:07 PM EDT
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.
Sam HobbsRank #107 · 20.5K reputationPosted Aug 24, 2011, 10:08 PM EDT
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.