From 8ab777b3b7160ac9ffa6e7ee0377de9ba64b08c1 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 4 Oct 2024 11:42:32 +0400 Subject: [PATCH] fix UserControlTable --- Components/Visual/ColumnInfo.cs | 8 +------- Components/Visual/UserControlTable.cs | 7 ++++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Components/Visual/ColumnInfo.cs b/Components/Visual/ColumnInfo.cs index 553b5dd..08a8955 100644 --- a/Components/Visual/ColumnInfo.cs +++ b/Components/Visual/ColumnInfo.cs @@ -12,12 +12,6 @@ namespace Components.Visual public int Width { get; set; } public bool Visible { get; set; } public string Name { get; set; } = string.Empty; - public ColumnInfo(string headerText, string name, int width, bool visible) - { - HeaderText = headerText; - Name = name; - Width = width; - Visible = visible; - } + public string DataPropertyName { get; set; } = string.Empty; } } diff --git a/Components/Visual/UserControlTable.cs b/Components/Visual/UserControlTable.cs index 7398b83..116c37f 100644 --- a/Components/Visual/UserControlTable.cs +++ b/Components/Visual/UserControlTable.cs @@ -42,6 +42,7 @@ namespace Components HeaderText = columnInfo[i].HeaderText, Width = columnInfo[i].Width, Visible = columnInfo[i].Visible, + DataPropertyName = columnInfo[i].DataPropertyName, }; dataGridViewTable.Columns.Add(column); } @@ -62,8 +63,8 @@ namespace Components int newRowInd = dataGridViewTable.Rows.Add(); 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 prop = props.FirstOrDefault(x => x.Name == col.DataPropertyName) + ?? throw new InvalidOperationException($"No property {col.DataPropertyName} found in type {typeof(T).Name}"); var val = prop.GetValue(value); dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val; } @@ -87,7 +88,7 @@ namespace Components for (int i = 0; i < dataGridViewTable.ColumnCount; i++) { var curCell = cells[i]; - var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].Name); + var prop = props.FirstOrDefault(x => x.Name == dataGridViewTable.Columns[i].DataPropertyName); prop?.SetValue(returnObject, curCell.Value); } return returnObject;