From 0233dae6734a91cd9927347334ba73bf8bdbbb26 Mon Sep 17 00:00:00 2001 From: Timourka Date: Tue, 26 Mar 2024 22:41:41 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=82?= =?UTF-8?q?=D0=B0=D0=BA=20=D1=87=D1=82=D0=BE=20=D0=B1=D1=8B=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D1=8F?= =?UTF-8?q?=D0=BB=D0=B8=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SUBD_Car_rent/Forms/FormCarModel.Designer.cs | 1 + SUBD_Car_rent/Forms/FormCarModel.cs | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/SUBD_Car_rent/Forms/FormCarModel.Designer.cs b/SUBD_Car_rent/Forms/FormCarModel.Designer.cs index 046213e..3bb3557 100644 --- a/SUBD_Car_rent/Forms/FormCarModel.Designer.cs +++ b/SUBD_Car_rent/Forms/FormCarModel.Designer.cs @@ -54,6 +54,7 @@ dataGridView.RowTemplate.Height = 25; dataGridView.Size = new Size(603, 426); dataGridView.TabIndex = 0; + dataGridView.CellClick += dataGridView_CellClick; // // label1 // diff --git a/SUBD_Car_rent/Forms/FormCarModel.cs b/SUBD_Car_rent/Forms/FormCarModel.cs index 8bc0d8a..fc1cec5 100644 --- a/SUBD_Car_rent/Forms/FormCarModel.cs +++ b/SUBD_Car_rent/Forms/FormCarModel.cs @@ -37,6 +37,15 @@ namespace Forms } } + private void loadFromRow() + { + textBoxBrand.Text = ""; + textBoxModel.Text = ""; + textBoxYear.Text = ""; + textBoxSeats.Text = ""; + comboBoxBodyType.DataSource = bd.GetBodyTypes().Select(x => x.Title).ToList(); + } + private void buttonCreate_Click(object sender, EventArgs e) { @@ -56,5 +65,28 @@ namespace Forms { loadData(); } + + private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + + // Заполняем текстовые поля данными из выбранной строки + textBoxBrand.Text = row.Cells["Brand"].Value.ToString(); + textBoxModel.Text = row.Cells["Model"].Value.ToString(); + textBoxYear.Text = row.Cells["Year"].Value.ToString(); + textBoxSeats.Text = row.Cells["Seats"].Value.ToString(); + + // Получаем значение типа кузова из выбранной строки + string selectedBodyType = row.Cells["BodyType"].Value.ToString(); + + // Загружаем список типов кузовов в комбо-бокс + comboBoxBodyType.DataSource = bd.GetBodyTypes().Select(x => x.Title).ToList(); + + // Выбираем тип кузова, который соответствует выбранному значению в строке + comboBoxBodyType.SelectedItem = selectedBodyType; + } + } } }