From 9b30023ed6d72663fe84e61b21779bbf993ee730 Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 9 Oct 2024 19:42:11 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BD=D1=8F=D1=82=D0=B0?= =?UTF-8?q?=D1=8F=201=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Components/CustomDataGridView.cs | 16 +++++++++++++--- Components/CustomTextBox.cs | 12 ++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Components/CustomDataGridView.cs b/Components/CustomDataGridView.cs index 026e9d6..925f9a5 100644 --- a/Components/CustomDataGridView.cs +++ b/Components/CustomDataGridView.cs @@ -93,10 +93,20 @@ namespace Components var properties = typeof(T).GetProperties(); - foreach (var obj in objects) + for (int i = 0; i < objects.Count; ++i) { - var values = properties.Select(p => p.GetValue(obj, null)).ToArray(); - dataGridView.Rows.Add(values); + var row = objects[i]; + dataGridView.Rows.Add(); + + for (int j = 0; j < dataGridView.ColumnCount; ++j) + { + var property = properties.FirstOrDefault(p => p.Name == dataGridView.Columns[j].DataPropertyName); + + if (property != null) + { + dataGridView.Rows[i].Cells[j].Value = property.GetValue(row, null); + } + } } } } diff --git a/Components/CustomTextBox.cs b/Components/CustomTextBox.cs index 2ff1dfd..94529e7 100644 --- a/Components/CustomTextBox.cs +++ b/Components/CustomTextBox.cs @@ -45,16 +45,8 @@ namespace Components } set { - if (value.HasValue) - { - checkBoxNull.Checked = false; - textBoxInteger.Text = value.ToString(); - } - else - { - checkBoxNull.Checked = true; - textBoxInteger.Text = string.Empty; - } + checkBoxNull.Checked = !value.HasValue; + textBoxInteger.Text = value.HasValue ? value.ToString() : string.Empty; } }