Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Gridview not adding new row in C#

$
0
0

I am using Microsoft Visual Studio Professional 2017 C#. This is a weird one. I am trying to add a row to my Gridview table. However, the row only showing up when I switch to a new tab and then come back to that tab. So I have 5 tabs. And if I switch to another tab and then come back to that same tab then, I see my new row. I tried to do this :

 public void UpdateGrid(int number)
    {
        try
        {
            if (InvokeRequired)
            {


                BeginInvoke(new Action(() =>
                {
                    if (number == 1)
                        dataGridView1.Update();
                    else
                        dataGridView2.Update();
                }));

                return;
            }
            if (number == 1)
                dataGridView1.Update();
            else
                dataGridView2.Update();
        }
        catch (Exception y)
        {

        }
    }

but it still does the same thing. The new row will not show up until I switch to a new tab and return to that tab. I am using threading and that is what I have my update like that.

here is my code:

void add_To_table(string site, string X, string Y, float Ts625, float Tp625, float CR625, float Ts1550, float Tp1550, float CR1550, string Xum, string Yum, int tablePick )
    {
        try
        {

            if (tablePick == 1)
            {
                table.Rows.Add(site, X, Y, Ts625, Tp625, CR625, Ts1550, Tp1550, CR1550, Xum, Yum);
                dataGridView1.DataSource = table;
            }
            else
            {
                table2.Rows.Add(site, X, Y, Ts625, Tp625, CR625, Ts1550, Tp1550, CR1550, Xum, Yum);
                dataGridView2.DataSource = table2;
            }
        }
        catch(Exception err)
        {
            MessageBox.Show(err.Message);
        }

    }


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>