private void FormTravel_Load(object sender, EventArgs e) { if (id.HasValue) { try { TravelViewModel view = logic.Read(new TravelBindingModel { Id = id.Value })?[0]; if (view != null) { textBoxName.Text = view.TravelName; textBoxPrice.Text = view.FinalCost.ToString(); TravelTours = view.TravelTours; LoadData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { TravelTours = new List <TravelTourViewModel>(); } }
private void LoadData() { try { var list = logic.Read(null); if (list != null) { dataGridView.DataSource = list; dataGridView.Columns[0].Visible = false; dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns[3].Visible = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }