runtime issue
-
I am creating a new tab onclick of a menu item at run time.....and in this tab i have to add a datagridview..and there is text box and execute button outside this tab... when i write any query and press execute then the result should be displayed on dridview..bt the problem is i m creating gridview at run time while user clicks an new query tab on menu...so problem is how to take reference of this gridview when i m doing coding on execute button...Like...Here i Have create that tabpage.
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Class1.res++;string s="ResultSet"+" "+Class1.res; TabPage tp = new TabPage(s); tabControl1.TabPages.Add(tp); tabControl1.SelectedTab = tp; }
and on execute button i am doing this code..
OdbcCommand cm = new OdbcCommand(richTextBox1.Text,cn);
cm.ExecuteNonQuery();
OdbcDataAdapter ad =new OdbcDataAdapter(richTextBox1.Text, cn);
DataSet dst = new DataSet();
if (dst.Tables["R"] != null)
{ dst.Tables["R"].Clear();
}
ad.Fill(dst, "R");
if (dst.Tables["R"].Rows.Count > 0) {
DataGridView dgv = new DataGridView();
dgv.ReadOnly = true;
dgv.BackgroundColor = Color.White;
dgv.DataSource = dst;
dgv.DataMember = "R";}
..While i am doing this it is not showing any result.....actually i have to add gridview on tab page...bt according to this code tab page is not available at design time......so plz provide any solution...
-
I am creating a new tab onclick of a menu item at run time.....and in this tab i have to add a datagridview..and there is text box and execute button outside this tab... when i write any query and press execute then the result should be displayed on dridview..bt the problem is i m creating gridview at run time while user clicks an new query tab on menu...so problem is how to take reference of this gridview when i m doing coding on execute button...Like...Here i Have create that tabpage.
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Class1.res++;string s="ResultSet"+" "+Class1.res; TabPage tp = new TabPage(s); tabControl1.TabPages.Add(tp); tabControl1.SelectedTab = tp; }
and on execute button i am doing this code..
OdbcCommand cm = new OdbcCommand(richTextBox1.Text,cn);
cm.ExecuteNonQuery();
OdbcDataAdapter ad =new OdbcDataAdapter(richTextBox1.Text, cn);
DataSet dst = new DataSet();
if (dst.Tables["R"] != null)
{ dst.Tables["R"].Clear();
}
ad.Fill(dst, "R");
if (dst.Tables["R"].Rows.Count > 0) {
DataGridView dgv = new DataGridView();
dgv.ReadOnly = true;
dgv.BackgroundColor = Color.White;
dgv.DataSource = dst;
dgv.DataMember = "R";}
..While i am doing this it is not showing any result.....actually i have to add gridview on tab page...bt according to this code tab page is not available at design time......so plz provide any solution...
You don't seem to have added the DataGridView to the Controls of the TabPage. What I have done in the past is derive a custom TabPage that has a DataGridView already on it and which accepts a DataTable in its constructor.
public partial class tpDataTable : System.Windows.Forms.TabPage
{
private System.Windows.Forms.DataGridView dataGridView1;
private System.ComponentModel.IContainer components = null ;public tpDataTable ( System.Data.DataTable Table ) { InitializeComponent() ; this.dataGridView1.DataSource = Table ;
...
this.tcResults.TabPages.Add ( new tpDataTable ( dt ) ) ;
-
You don't seem to have added the DataGridView to the Controls of the TabPage. What I have done in the past is derive a custom TabPage that has a DataGridView already on it and which accepts a DataTable in its constructor.
public partial class tpDataTable : System.Windows.Forms.TabPage
{
private System.Windows.Forms.DataGridView dataGridView1;
private System.ComponentModel.IContainer components = null ;public tpDataTable ( System.Data.DataTable Table ) { InitializeComponent() ; this.dataGridView1.DataSource = Table ;
...
this.tcResults.TabPages.Add ( new tpDataTable ( dt ) ) ;