C# How to add DataTable to TabPage Controls

498 Views Asked by At

I have an access db and I get the datas from there to DataGridView like below code. I get that datas from tabpage's control. How can I add DataTable to tabpage's control. I want to do that because getting data from datagridview is very slow.

adding data to datagridview and adding the datagridview to tabpage's control

        da = new OleDbDataAdapter("SELECT Robotlar FROM A_Robotlar", con);
        ds = new DataSet();
        con.Open();
        da.Fill(ds, "A_Robotlar");            

        DataTable dt = ds.Tables["A_Robotlar"];
        int count = dt.Rows.Count;
        if (count > 0)
        {
            tabControl1.TabPages.Clear();

            for (int i = 0; i < count; i++)
            {
                da = new OleDbDataAdapter("SELECT *FROM " + dt.Rows[i][0].ToString(), con);
                ds = new DataSet();
                da.Fill(ds, dt.Rows[i][0].ToString());

                tabControl1.TabPages.Add(dt.Rows[i][0].ToString());
                tabControl1.TabPages[i].Controls.Add(new DataGridView()
                {
                    Name = "grid_" + dt.Rows[i][0].ToString(),
                    Dock = DockStyle.Fill,
                    AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                    RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing,
                    ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
                    AllowUserToResizeRows = false,
                    AllowUserToResizeColumns = false,
                    RowHeadersVisible = false,
                    DataSource = ds.Tables[dt.Rows[i][0].ToString()]
                });

            }
        }

        con.Close();

Get data from controls

            foreach (TabPage tbp in tabControl1.TabPages)
            {                    
                foreach (Control ctrl in tbp.Controls)
                {                        
                    if (ctrl is DataGridView)
                    {                            
                        DataGridView newDgv = ctrl as DataGridView;
                        
                        for (int i = 0; i < newDgv.Rows.Count-1; i++)
                        {
                            chromeTarayici.FindElement(By.ClassName("_3FRCZ")).SendKeys(newDgv.Rows[i].Cells[4].Value.ToString() + OpenQA.Selenium.Keys.Enter);
                            Thread.Sleep(50);

                            chromeTarayici.FindElement(By.ClassName("_3uMse")).SendKeys(tbp.Text + " " + Sinyal);
                            Thread.Sleep(100);

                            chromeTarayici.FindElement(By.ClassName("_3uMse")).SendKeys(OpenQA.Selenium.Keys.Enter);
                            Thread.Sleep(50);
                        }
                    }
                }
            }
0

There are 0 best solutions below