I have a datagridview which is populated with records from .csv file (around 30k records with 30-40 unique id's - depends on file). It looks like this:
Now my question is how to sum up those columns by id? Or maybe there is a way to directly put already sumed up values to datagridview?
private void dropListBox_DragDrop(object sender, DragEventArgs e)
{
data= new List<Raport>();
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
var nameOnly = System.IO.Path.GetFileName(file);
dropListBox.Items.Clear();
dropListBox.Items.Add(nameOnly);
dataGridView1.Rows.Clear();
string[] readText = File.ReadAllLines(file, Encoding.GetEncoding("Windows-1250"));
int i = 0;
foreach (string line in readText)
{
if (i++ == 0) continue;
var values = line.Split(';');
string a= values[0];
string b= values[1];
string c= values[2];
string user = values[3];
int xValues= int.Parse(values[4]);
int yValues= int.Parse(values[5]);
double d= double.Parse(values[6]);
string e= values[7];
string f= values[8];
string g= values[9];
string h= values[10];
double i= double.Parse(values[11]);
string j= values[12];
Raport Raport = new Raport(
a,
b,
c,
user,
xValues,
yValues,
d,
e,
f,
g,
h,
i,
j);
data.Add(Raport);
dataGridView1.Rows.Add(Raport.user, Raport.xValues, Raport.yValues, "8", "8");
This is the code I have. The last 2 columns doesn't matter (It's always filled with fixed values)
Any suggestions would be appreciated.
It should go like this
John | 5 | 4
Carl | 3 | 1
John | 1 | 6
Carl | 4 | 1
then
John | 6 | 10
Carl | 7 | 2
the structure of the Raport Class
class Raport
{
public readonly string a;
public readonly string b;
public readonly string c;
public readonly string user;
public readonly int xValue;
public readonly int yValue;
public readonly double d;
public readonly string e;
public readonly string f;
public readonly string g;
public readonly string h;
public readonly double i;
public readonly string j;
public Raport(
string a,
string b,
string c,
string user,
int xValue,
int yValue,
double d,
string e,
string f,
string g,
string h,
double i,
string j)
{
this.a= a;
this.b= b;
this.c= c;
this.user= user;
this.xValue= xValue;
this.yValue= yValue;
this.d= d;
this.e= e;
this.f= f;
this.g= g;
this.h= h;
this.i= i;
this.j= j;
}
public Raport()
{
}
public override string ToString()
{
return a+ " ; " +
b+ " ; " +
c+ " ; " +
user+ " ; " +
xValue+ " ; " +
yValue+ " ; " +
d+ " ; " +
e+ " ; " +
f+ " ; " +
g+ " ; " +
h+ " ; " +
i+ " ; " +
j;
}
}
}