开发者

Combobox manual binding

I am trying to do something which I believe is not complicated but still - the straight forward approach doesnt seem to work...

I created a user control and bound it to a datatable, then I created a new Binding and binded another object to that same combo (SelectedValue to be more exact) in the following manner:

this.cboValue.DataSource = dt;
this.cboValue.ValueMember = "ID";
this.cboValue.DisplayMember = "Text";
valueBinding = new Binding("SelectedValue", value, "Value", false, DataSourceUpdateMode.OnPropertyChanged);
this.cboValue.DataBindings.Add(valueBinding);
valueBinding.BindingComplete += new BindingCompleteEventHandler(valueBinding_BindingComplete);
开发者_Python百科

That was working perfectly fine updating the object when needed. Then I needed to use a different approach for binding since some controls needed to be populated manually, so I created a new business object and tried binding a list / array of that object to the control.

The thing is that altough setting the ValueMember I get DBNull.Value instead of the value I was aiming for when setting up the binding.

I did manage to create a workaround - creating a new datatable for that list / array of business object and keep the binding to the table, but still it seems like a hassle.

Anyone ever tried something similar?


i think your main issue is that data table implement some interfaces that the standard array/List do not.

try working with BindingList<>. and also make youe class implement the INotifyPropertyChanged interface.

i hope it will solve all your problems

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜