简体   繁体   English

C# .net Combobox 在绑定到数据集时显示 valuemember 而不是 displaymember

[英]C# .net Combobox displays valuemember not displaymember when bound to dataset

I'm trying to populate a combo box from a dataset, then bind it to a different data row.我正在尝试从数据集中填充组合框,然后将其绑定到不同的数据行。 The datarow contains a single customer records.数据行包含单个客户记录。 The dataset contains 1 table with title_id (an int) and title (the text description).数据集包含 1 个表,其中包含 title_id(一个 int)和 title(文本描述)。

I set the value and display members, and the datasource of the combo box:我设置值和显示成员,以及组合框的数据源:

cbxTitle.ValueMember = "title_id";
cbxTitle.DisplayMember = "title";
cbxTitle.DataSource = dsTitles.Tables[0];

Next I set the data binding to the data row with the customers details:接下来我将数据绑定到包含客户详细信息的数据行:

cbxTitle.DataBindings.Add("Text", drCustomer.Table, "title_id");

When I run it, the combo box displays the number 2 (the value of title_id in the data row).当我运行它时,组合框显示数字 2(数据行中 title_id 的值)。

If I click it, it contains Mr, Mrs, Miss etc as i'd expect (Mr = 2)如果我点击它,它会像我期望的那样包含先生、夫人、小姐等 (Mr = 2)

What I can't figure out is how to get it to display 'Mr' instead of 2?!我想不通的是如何让它显示“先生”而不是 2?!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM