public Form1() { InitializeComponent(); try { jobs = JobItems.LoadFile(fileName); } catch (Exception ex) { MessageBox.Show(ex.Message); OpenFile(); } jobGridView.DataSource = jobs; jobGridView.Columns["JobName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; jobGridView.Columns["JobName"].DefaultCellStyle.WrapMode = DataGridViewTriState.True; jobGridView.Columns["Industry"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; jobGridView.Columns["Industry"].DefaultCellStyle.WrapMode = DataGridViewTriState.True; jobGridView.Columns["SalaryTotal"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; jobGridView.Columns["Region"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; jobGridView.RowTemplate.Height = 40; //jobGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; //jobGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True; UpdateCombos(); UpdateTracks(); UpdateTable(); openCSV.Filter = "*csv filter(*.csv) | *.csv"; }
public static List <JobItems> LoadFile(String FileName) { List <JobItems> items = new List <JobItems>(); var config = new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = ";", BadDataFound = null }; using (var reader = new StreamReader(FileName, Encoding.GetEncoding("windows-1251"))) using (var csv = new CsvReader(reader, config)) { csv.Read(); csv.ReadHeader(); while (csv.Read()) { if (!float.TryParse(csv.GetField("SalaryTotal"), out float salaryTotal)) { salaryTotal = 0; } var jobItem = new JobItems { SalaryTotal = salaryTotal, JobName = csv.GetField("JobName"), Region = csv.GetField("Region3"), Industry = csv.GetField("Industry"), }; items.Add(jobItem); } } return(items); }
public void OpenFile() { if (openCSV.ShowDialog() == DialogResult.Cancel) { return; } fileName = openCSV.FileName; jobs = JobItems.LoadFile(fileName); }