Click here to Skip to main content
12,359,056 members (46,821 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# SQL .NET
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:52am
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.
onurag19 20-Sep-12 8:27am
   
please explain it more properly
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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  
v2
Comments
Wes Aday 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?
onurag19 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160621.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100