c# - 用来自mysql c#的数据列表填充组合框
问题描述
我有这个方法
public List<Trgovina> getAllStores()
{
using (IDbConnection connection = new MySqlConnection(Helper.CnnVal("dbConn")))
{
return connection.Query<Trgovina>("TrgovineViewAll", null,
commandType: CommandType.StoredProcedure
)
.ToList();
}
}
它从数据库中获取所有商店信息。它在启动时调用的方法
public MainWindow()
{
InitializeComponent();
List<Trgovina> stores = new List<Trgovina>();
stores = da.getAllStores();
comboxStoreNames.ItemsSource = stores;
}
商店充满了数据。虽然数据不是我需要的格式。它只是显示{Project_Budget.Engine.Trgovina}
。我需要的信息就在里面。如何以字符串格式从那里获取该数据,以便在组合框中显示它?
解决方案
你必须使用组合框的DisplayMember
和ValueMember
属性,它允许你绑定你想要的属性。
推荐阅读
- python - 使用 .sort() 函数中的键对 python 中的列表列表进行排序
- r - 为什么 dbpylr 中的过滤功能将数据帧转换为值列表并将所有值更改为 R 中的 NA?
- python - Python中基于参数的条件继承
- node.js - gRPC 二进制文件未加载
- python - Python ValueError:操作数无法与形状(3,)(2,)一起广播
- javascript - 如何使用 package:js 在 Dart 中映射返回异步迭代器的 JavaScript 函数?
- laravel - Composer 在您的平台中检测到问题:您的 Composer 依赖项需要 PHP 版本 ">= 7.2.5"
- javascript - 如何在 VueJS 中使用 Auth0 对 apollo 进行身份验证
- flutter - Flutter - 如何通过从 TextField 中获取值将行添加到 PaginatedDataTable?
- ubuntu - nmap "无法打开输出文件 /home/(user)/file