简体   繁体   中英

C# Entity Framework 6 two way binding with listbox

How can I bind an entity to a listbox that allows two way operation?

I know I can provide a datasource, but that doesn't work (two ways I mean).

I was able to achieve what I wanted with a text box using listbox.Databindings.Add("Text", entity, "TextField") .

I've tried binding to SelectedValue, SelectedItem, SelectedItems and Items. None of those work. In some cases I get an exception

TargetInvocationException

With an inner exception text of Object does not match target type.

The object is a date/time object, but that doesn't seem to be a problem when I bind using DataSource .

Any help would be most appreciated.

DataSource is the source of the items of the listbox. When you choose an element from the listbox, the selected element is SelectedItem. Usually you set the DataSource (usually the target of a foreign key) and bind the SelectedItem (the foreign key).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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