Featured post
vb.net - Why isn't this Linq query on Dictionary<TKey, TValue> working as DataSource -
i have following in vb:
dim sources = source in importsources select new _ {.type = source.key, .source = source.value.name} dgridsourcefiles.datasource = sources
when debug, sources
shows in-memory query , has 2 records within. yet datagrid view not show records.
so why won't work? suggestions can either vb or c#...
update
when use:
dim sources = (from source in importsources select new _ {.type = source.key, .source = source.value.name}).tolist()
...the datasource displayed.
your linq query lazily evaluated , implements ienumerable<t>
interface (as far know), means results not established until enumerator calls movenext
somewhere (as happens within foreach
loop, example).
it seems datasource
property not enumerate contents in way. it's expecting implementation of ilist
(or 1 of few other interfaces—see below) can access items index. used internally control sorting, filtering, etc. in mind, it's setting datasource
property check object's type see whether implements of supported interfaces. don't think datasource
property designed deal type of object (a lazily evaluated query) @ all.
now, tolist
call populates list<t>
results of query; does implement ilist
, can therefore used datasource
.
my understanding reason datasource
typed merely object
expects any of following interfaces:
ilist
ilistsource
(in caseilistsource.getlist
method useddatamember
property provide data control)ibindinglist
(which propagates changes in list control ui updates)ibindinglistview
(likebindingsource
)
this according msdn documentation.
- Get link
- X
- Other Apps
Comments
Post a Comment