简体   繁体   中英

Average row values with same time in datagridview

I am writing this software which reads a CSV file and puts it into a datagridview. Here you can see the picture of the application:

在此处输入图片说明

I am achieving this with the following code, firstly:

private string[,] LoadCsv(string filename)
        {           
            string whole_file = System.IO.File.ReadAllText(filename);


            whole_file = whole_file.Replace('\n', '\r');
            string[] lines = whole_file.Split(new char[] { '\r' },
                StringSplitOptions.RemoveEmptyEntries);


            int num_rows = lines.Length;
            int num_cols = lines[0].Split(';').Length;


            string[,] values = new string[num_rows, num_cols];


            for (int r = 0; r < num_rows; r++)
            {
                string[] line_r = lines[r].Split(';');
                for (int c = 0; c < num_cols; c++)
                {
                    values[r, c] = line_r[c];
                }
            }           
            return values;
        }

and then this:

private void btnGo_Click(object sender, EventArgs e)
        {

            string[,] values = LoadCsv(txtFile.Text);
            int num_rows = values.GetUpperBound(0) + 1;
            int num_cols = values.GetUpperBound(1) + 1;

            dgv.Columns.Clear();
            for (int c = 0; c < num_cols; c++)
                dgv.Columns.Add(values[0, c], values[0, c]);


            for (int r = 1; r < num_rows; r++)
            {
                dgv.Rows.Add();
                for (int c = 0; c < num_cols; c++)
                {
                    dgv.Rows[r - 1].Cells[c].Value = values[r, c];
                }
            }
        }   

What I am asking now is if there is the possibility to average the values minute by minute inside the datagridview or with another interval of time (needs to be a low interval 1 to 5 minutes).

Thanks for your help!

If i understood you right you want to read the csv every x minutes again ? Maybe you can use a timer like this

var timer = new System.Threading.Timer((e) => { LoadCsv(string filename) }, null, 0, TimeSpan.FromMinutes(5).TotalMilliseconds);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM