работает форма добавления и редактирования полностью, пофиксила компонент выбора из списка

This commit is contained in:
Елена Бакальская 2024-11-20 13:39:30 +04:00
parent 9c3a569942
commit 394ecca149
2 changed files with 12 additions and 8 deletions

View File

@ -19,9 +19,7 @@ namespace AppShopInternetOption19
_orderStatusLogic = orderStatusLogic;
InitializeComponent();
List<string> statuses = new List<string>() { "готов", "не готов" };
selectComponentOrderStatus.FillList(statuses);
selectComponentOrderStatus.FillList(_orderStatusLogic.ReadList(null), "Name");
textBoxFIO.TextChanged += valueChanged;
textBoxGoodDescription.TextChanged += valueChanged;
@ -119,8 +117,7 @@ namespace AppShopInternetOption19
}
catch (Exception ex)
{
throw;
MessageBox.Show(ex.Message);
}
}
}

View File

@ -13,11 +13,18 @@
//comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;
}
public void FillList(List<string> list)
public void FillList<Y>(List<Y> list, string property) where Y : class
{
foreach (string item in list)
ClearList();
foreach (var item in list)
{
comboBox.Items.Add(item);
var propName = item.GetType().GetProperty(property);
if(propName != null)
{
var value = propName.GetValue(item)?.ToString();
comboBox.Items.Add(value);
}
}
//comboBox.SelectedIndex = rand.Next(list.Count);
}