Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. runtime issue

runtime issue

Scheduled Pinned Locked Moved C#
helpdatabasedesigntutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nitish_07
    wrote on last edited by
    #1

    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...

    P 1 Reply Last reply
    0
    • N nitish_07

      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...

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      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 ) ) ;

      N 1 Reply Last reply
      0
      • P PIEBALDconsult

        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 ) ) ;

        N Offline
        N Offline
        nitish_07
        wrote on last edited by
        #3

        thanks for d reply....But i have solved my problem....actually i had missed that code....but i solved my problem just defining gridview globally and assingning memory to it when i need it....

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups