I would like to show DataTable depends on row value on specific column from a file. Key is that I have two different files, with different values.
For example:
1 file with structure:
Id;Name;Surname;Sex;Age;
1;AAA;EEE;Male;20;
2;BBB;FFF;Male;20;
3;CCC;GGG;Male;40;
4;DDD;HHH;Male;40;
2 File with structure:
Id;Name;Surname;Sex;Age;
1;AAA;EEE;Female;20;
2;BBB;FFF;Female;20;
3;CCC;GGG;Female;40;
4;DDD;HHH;Female;40;
If I will open file which contains in Column Sex value Male then it should show only rows with value 20. 40 is skipped.
If I will open second file which contains in Column Sex value Female then it should show only rows with value 40. 20 is skipped.
So, mainly it should looks like: If I will open 1 file it should show:
Id;Name;Surname;Sex;Age;
1;AAA;EEE;Male;20;
2;BBB;FFF;Male;20;
If I will open 2 file it should show:
Id;Name;Surname;Sex;Age;
3;CCC;GGG;Female;40;
4;DDD;HHH;Female;40;
My code so far:
table = new DataTable();
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Text file|*.txt";
openFileDialog1.Title = "Import file";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
reader = new System.IO.StreamReader(openFileDialog1.FileName);
NameFile = reader.ReadToEnd();
}
var lines = System.IO.File.ReadAllLines(openFileDialog1.FileName);
if (lines.Count() > 0)
{
.
.
.//some code here not important
.
.
.
}
dataGridView1.DataSource = table;
}
DataView dv = table.DefaultView;
dv.RowFilter = "[Sex] LIKE 'Male' OR [Sex] LIKE 'Female'";
dataGridView1.DataSource = dv;
dataGridView1.AutoResizeColumns();
But It shows only Male or Female sex, it should as well somehow filter Age by 20 or 40. Do you have any ideas?