首页 > 解决方案 > 用来自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}。我需要的信息就在里面。如何以字符串格式从那里获取该数据,以便在组合框中显示它?

标签: c#mysqldapper

解决方案


你必须使用组合框的DisplayMemberValueMember属性,它允许你绑定你想要的属性。


推荐阅读