private void DeletetoolStripButton4_Click(object sender, EventArgs e) { bool a = false; if (selectIndex != -1) { using (CsvReader csvCar = car.connect()) { while (csvCar.ReadNextRecord()) { if (selectId.ToString() == csvCar[IdColumn.id_AddressId]) { MessageBox.Show("Неможливо видалити, даний автосалон використовується!"); a = true; break; } } } if (!a) { DialogResult resut = MessageBox.Show("Автосалон " + dataGridViewAddress.Rows[selectIndex].Cells[2].Value + " не використовується.\nВидалити?", "Увага!", MessageBoxButtons.YesNo); if (resut == DialogResult.Yes) { address.Remove(selectId); dataGridViewAddress.Rows.RemoveAt(selectIndex); } } } }
// CsvReader csvAddress = new CsvReader(new StreamReader(@"D:\Student\Дипломна\car\car\data\Address.csv"), true, ';'); private void Address_Shown(object sender, EventArgs e) { dataGridViewAddress.ReadOnly = true; using (CsvReader csv = address.connect()) { dataGridViewAddress.ReadOnly = true; int n = csv.FieldCount; int i = 0; while (csv.ReadNextRecord()) { dataGridViewAddress.Rows.Add(); dataGridViewAddress.Rows[i].Cells[0].Value = i + 1; for (int j = 0; j < n; j++) { dataGridViewAddress.Rows[i].Cells[j + 1].Value = csv[j].ToString(); } i++; } } }