From 7895adaa07b6c83dcc6734ab092d2745a7359d00 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 06:48:52 +0400 Subject: [PATCH] AddList fix --- Components/Visual/UserControlTable.cs | 35 ++++++++++++--------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/Components/Visual/UserControlTable.cs b/Components/Visual/UserControlTable.cs index b5e7041..085905e 100644 --- a/Components/Visual/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -52,9 +52,22 @@ namespace Components dataGridViewTable.Rows.Clear(); } - public void AddObjectList(List os) + public void AddList(List values) { - dataGridViewTable.DataSource = os ?? throw new ArgumentNullException(); + ClearRows(); + var props = typeof(T).GetProperties(); + + foreach (T value in values) + { + int newRowInd = dataGridViewTable.Rows.Add(value); + foreach (DataGridViewColumn col in dataGridViewTable.Columns) + { + var prop = props.FirstOrDefault(x => x.Name == col.Name) + ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); + var val = prop.GetValue(value); + dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; + } + } } public T GetObjectFromRow() @@ -79,23 +92,5 @@ namespace Components } return returnObject; } - - public void AddList (List values) - { - ClearRows(); - var props = typeof(T).GetProperties(); - - foreach (T value in values) - { - int newRowInd = dataGridViewTable.Rows.Add(value); - foreach (DataGridViewColumn col in dataGridViewTable.Columns) - { - var prop = props.FirstOrDefault(x => x.Name == col.Name) - ?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}"); - var val = prop.GetValue(value); - dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; - } - } - } } }