Q: Display and refresh a data table after enough sampling I am working with an HMI that displays samples taken remotely from a PLC. Due to the sampling rate(5 seconds), when the code runs the for loop it fills the row with the same value as it takes some time to change. I was trying to add some 'last state' conditions but my code never really worked out.
Below is the code that displays a datatable, but every column of a single row shows the same value.    
    public DataTable dt = new DataTable();

    public void Bindgrid(DataTable dtnew)
    {
        if (dtnew != null)
        {
            dt = dtnew;
            PicBox.Refresh();
        }
    }

    public void loadgrid()
    {

    dt.Clear();
    dt.Rows.Clear();

    for (int i = 1; i <= 3; i++)
    {
        DataRow row = dt.NewRow();
        row["NO"] = i.ToString();
        for (int jval = 1; jval <= totalColumntoDisplay; jval++)
        {
            row[jval.ToString()] = measurement;
        }

        dt.Rows.Add(row);

    }

        dataGridView1.AutoResizeColumns();
        dataGridView1.DataSource = dt;
        dataGridView1.AutoResizeColumns();
    }

    public void loadGridColums()
    {
        dt.Columns.Add("No");

        for (int jval = 1; jval <= totalColumntoDisplay; jval++)
        {
            dt.Columns.Add(jval.ToString());
        }
    }

    private void timer2_Tick(object sender, EventArgs e)
    {
        measurement = "PLC sampling value";
        loadgrid();
        Bindgrid(dt);
        lastmeasurement = measurement;
    }

I changed the for loop with an if(lastmeasurement!=measurement)
if(lastmeasurement!=measurement)
{
    row[jval.ToString()] = measurement;
    jvalue++;
}

But the column value(jvalue) never changed.
The only thing I want to display is a datatable (or even an array) with different values, its MEAN and standard deviation, but I am having a hard time showing this data the way I want in a data table. Maybe there is an easier way to display this data. 
PS: I am storing the sampling values in a database which actually works with the last state condition, if it can be useful somehow.  
