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
Post a Comment