C#, .Net 4, VS2010
I have an object that contains multiple arrays of doubles (recently made them into Lists). It looks something like:
public class Channel
{
public List<DateTime> Date = new List<DateTime>(); //DateTime
public List<double> Val1 = new List<double>(); //
public List<double> Val2 = new List<double>(); //
public List<double> Val3 = new List<double>(); //
public List<double> Val4 = new List<double>(); //
}
So now I'm trying to populate a DataGridView
with a DataSource
, but I only care about Date
, Val1
, and Val2
. How can I achieve this?
Currently I'm looping through the arrays and adding them row by row to the DataGridView
. But this is really slow as I have a huge file of data to work with. Isn't there an easy way to just bind my arrays and populate the grid? I can't seem to figure it out.
Thanks
Code I've tried:
Channel ch = new Channel();
List<object> datasource = new List<object>();
dataGridView1.Rows.Clear();
dataGridView1.Columns.Clear();
datasource.Add(ch.spotsList[0].Date);
datasource.Add(ch.spotsList[0].Val1);
datasource.Add(ch.spotsList[0].Val2);
dataGridView1.DataSource = datasource;
Code I'm using that works but is really slow:
for (int i = 0; i < ch.spotsList[0].Date.Count; i++)
{
dataGridView1.Rows.Add(ch.spotsList[0].Date[i].ToString("yyyy-MM-dd HH:mm:ss"), ch.spotsList[0].Val1[i].ToString("#.##"), ch.spotsList[0].Val2[i].ToString("#.##"));
}