c# - Retrieve Databound List<T> from ListBox -


so here's question that's either extremely simplistic has never been asked before or else has been asked before, i'm asking question wrongly.

so databinding list<myobject> listbox control in winform.

like so:

list<myobject> list = new list<myobject>(); // add myobjects list... mylistbox.datasource = new bindingsource(list, null); 

then later want obtain access databound list.

i thought work...

list<myobject> results = (list<myobject>)mylistbox.datasource; 

in visual studio, can see datasource property of mylistbox contains list of myobjects, however, cast results in invalidcastexception.

is there effective way accomplish this? or should hold onto original list?

mylistbox.datasource bindingsource, not list<t>. need binding source, extract out data list property:

var bs = (bindingsource)mylistbox.datasource; list<myobject> results = (list<myobject>)bs.list; 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -