Click here to Skip to main content
Sign Up to vote bad
good
See more: C#SQL.NETNoEffort
hi,
i want to create a data grid view in my windows application dynamically(i.e. at run time). any help please....thnx in advance
Posted 20 Sep '12 - 0:52
Edited 20 Sep '12 - 0:53

Comments
Andrei Straut - 20 Sep '12 - 6:54
Did you try Googling[^] it first? The first result actually looks quite promising, as well as a few others down the page. I've downvoted your question for lack of any apparent effort on your part.
onurag19 - 20 Sep '12 - 8:27
please explain it more properly

3 solutions

use elow code for creating dynamic gridview
 




private void btnfind_Click(object sender, EventArgs e)
{
DataGridView gridview = new DataGridView();
//after taking PlaceHolder control in The page Writer following code
groupBox1.Controls.Add(gridview);
 

SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=FITA-AKEEL;Initial Catalog=managementsystem;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Select * from tblguesttype";
 

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
string tablename = "tblgueattype";
 
gridview.DataSource = ds;
gridview.DataBindings.ToString();

da.Fill(ds, tablename);
gridview.DataSource = ds;
gridview.DataMember = tablename;

}
  Permalink  
private void btnfind_Click(object sender, EventArgs e)
{
DataGridView gridview = new DataGridView();
//after taking group box control in the page, Write following code
groupBox1.Controls.Add(gridview);
 

SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=FITA-AKEEL;Initial Catalog=managementsystem;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Select * from tblguesttype";
 

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
string tablename = "tblgueattype";
 
gridview.DataSource = ds;
gridview.DataBindings.ToString();

da.Fill(ds, tablename);
gridview.DataSource = ds;
gridview.DataMember = tablename;

}
  Permalink  
con = new MySqlConnection();
con.ConnectionString =ConfigurationSettings.AppSettings["constr"];
con.Open();
string str = "select * from pto ";
MySqlDataAdapter da = new MySqlDataAdapter(str, con);
DataSet ds=new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
  Permalink  
Comments
Wes Aday - 20 Sep '12 - 16:04
Copied from OP, "create a data grid view in my windows application dynamically".... Where is it in your solution are you creating dataGridView1 dynamically as was asked in the question?
onurag19 - 20 Sep '12 - 19:53
Why don;t you provide an answer Sir:)
Skand Pratap Singh - 21 Sep '12 - 2:11
plesae help me in creating it dynamically

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 479
1 Arun Vasu 253
2 OriginalGriff 210
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,129
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 2,999


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid