Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL .NET NoEffort
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
Edited 20-Sep-12 0:53am
v2
Comments
Andrei Straut at 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 at 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 at 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 at 20-Sep-12 19:53pm
   
Why don;t you provide an answer Sir:)
Skand Pratap Singh at 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
0 OriginalGriff 723
1 George Jonsson 370
2 BillWoodruff 277
3 Garth J Lancaster 250
4 Sergey Alexandrovich Kryukov 249
0 Sergey Alexandrovich Kryukov 10,764
1 Maciej Los 5,474
2 OriginalGriff 5,472
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web03 | 2.8.141030.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
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