0

我是 C# 新手,正在创建一个测试应用程序来从 Access 数据库中的表中填充组合框。我希望能够即时设置这些信息。作为测试人员,我创建了一个新表单,添加了一个名为“TBCallOutcome”的组合框,并添加了代码。

但是,它似乎在每一行中都使用“System.Data.DataRowView”填充下拉列表。

任何想法 - 谢谢?

    private void Form1_Load(object sender, EventArgs e)
    {
        string query = "SELECT [Call outcome] FROM [DD Call Outcomes] WHERE ((([Show on list])=True)) ORDER BY [Sort order]";
        OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='N:\\Test\\Dropdowns.mdb';User Id=admin; Password=;");
        DataTable source = new DataTable();
        dAdapter.Fill(source);
        TBCallOutcome.DataSource = source;
    }
4

1 回答 1

-1

您必须设置DisplayMemberComboBox

private void Form1_Load(object sender, EventArgs e)
{
    string query = "SELECT [Call outcome] FROM [DD Call Outcomes] WHERE ((([Show on list])=True)) ORDER BY [Sort order]";
    OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='N:\\Test\\Dropdowns.mdb';User Id=admin; Password=;");
    DataTable source = new DataTable();
    dAdapter.Fill(source);

    TBCallOutcome.ValueMember = "[Call outcome]";
    TBCallOutcome.DisplayMember = "[Call outcome]";
    TBCallOutcome.DataSource = source;
}
于 2013-10-09T09:17:48.723 回答