Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
2.14/5 (7 votes)
See more:
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
Updated 20-Sep-12 0:53am
v2
Comments
Andrei Straut 20-Sep-12 6:54am    
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.
[no name] 20-Sep-12 8:27am    
please explain it more properly

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;

}
 
Share this answer
 
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;

}
 
Share this answer
 
C#
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];
 
Share this answer
 
v2
Comments
[no name] 20-Sep-12 16:04pm    
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?
[no name] 20-Sep-12 19:53pm    
Why don;t you provide an answer Sir:)
Skand Pratap Singh 21-Sep-12 2:11am    
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900