문제

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).

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).

If I click it, it contains Mr, Mrs, Miss etc as i'd expect (Mr = 2)

What I can't figure out is how to get it to display 'Mr' instead of 2?!

도움이 되었습니까?

해결책

How about:

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

Please refer to these links too:

Entity Framework 4 Databinding on WinForms ComboBoxes with Foreign Keys

Why does the ComboBox.SelectedValue DataBinding context gets cleared when BindingList changes?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top