/// <summary> /// Read file handler, will check if the csv consists from one line and update the front end elements /// </summary> /// <param name="filePath"></param> private void ReadFile(string filePath) { int lineChanges = MainFunction.CountLineChanges(filePath); if (lineChanges < 2) { // handle one line csv MainFunction.OneLineCsvHandling(); MessageBox.Show("The csv is consisting from one single line, please specify the correct field count", "Cannot split csv!"); // clear data grid view dataGridView1.Refresh(); dataGridView1.DataSource = null; // refresh the combobox cbxFieldsCount.Items.Clear(); foreach (var item in MainFunction.fieldDividers) { cbxFieldsCount.Items.Add(item); } // Update the statusbar statusBar1.Text = "Please choose the correct column number ->"; } else { MainFunction.GenerateCsvObjectFromString(); updateDataGridView(MainFunction._parsedCsv); } }
/// <summary> /// Combobox Automation, will execute on choosing one of the items in the dropdown menu /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cbxFieldsCount_SelectedValueChanged(object sender, EventArgs e) { int fieldsCount = (int)cbxFieldsCount.SelectedItem; MainFunction.GenerateCsvObject(fieldsCount); updateDataGridView(MainFunction._parsedCsv); }
/// <summary> /// Combobox Automation, will execute on entering a numeric value and press Enter /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cbxFieldsCount_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { int fieldsCount = 0; if (Int32.TryParse(cbxFieldsCount.Text, out fieldsCount)) { if (fieldsCount <= MainFunction._maxAllowedFields) { MainFunction.GenerateCsvObject(fieldsCount); updateDataGridView(MainFunction._parsedCsv); } else { MessageBox.Show("Please enter a lower field number", "Dupplicate column name"); } } } }