Linq sql data binding to winforms combobox

2019-08-21 03:50发布

I am trying to bind a ComboxBox to a foreign key table. I know that on cannot bind to the actual foreign key, SomeTableClassFK, (causes a LinqSql exception when the FK already has a value). So, I am binding to FK object, SomeTable, reference thru the SelectedItem property of the ComboBox.

SomePrimaryTable
SomeTableClassFK ---> SomeTableClass.PK
SomeTable --------> SomeTableClass

this.aComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.somePrimaryTableBindingSource, "PendingReason", false));

This isn't working. The ComboBox always insta-binds the FK object to the first item in its list.

Any ideas?

标签: linq-to-sql
2条回答
何必那么认真
2楼-- · 2019-08-21 04:27

i don't know exactly in which post, but I remember that scottgui came up with solution to this problem in linq series...maybe to try to find it:

http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx

cheers

查看更多
Emotional °昔
3楼-- · 2019-08-21 04:28

Ok...Issue was traced to funky winform behavior. Evidently, there is no guarantee that the OnLoad for a user control will not be called more than once. As a consequence, the two tables involved, (see diagram above), were being loaded from different DataContexts. Splat!!

查看更多
登录 后发表回答