I have a small app in which I have a gridview. The grid is binded to a source that looks like this (a list of):
Person{name; email; orders;} – orders is an IEnumerable.
The challenge now, is that I want the grid to load without first loading the orders list. This is where the aysnc is coming into picture. When the grid has loaded and shows the persons name and email, then it should behind the scenes start loading up the orders from each person. When the orders are ready they should be shown.
I have tried a couple of ways:
-
load everything with async, this is an ok approach but the grid is first showing when the all the data in the source is ready. Why ?
-
load persons source (list) without orders list and try to load orders for each person after the grid has shown. I fail to do this, because I can’t seem to find the right “hook”, in WebForms a datagrid would have a “OnItemDataBound” event I could hook into. Any clue ?
-
Dispatcher behind the scenes stuff…to complex and rigid.
It might be control feature that I have overlooked.
Any help is much appreciated. No code avalible at this moment ( forgot it at home 🙂 )
This is how I would do it (in SILVERLIGHT):
If you use an ObservableCollection then the Orders will show when each collection is populated. I’m assuming that you have some sort of key to determine which orders go with which person.
It would be something like this when the orders come back:
This is psudo-vb code, and is just an example. Basically the key is to use an ObservableCollection for the orders instead of a generic IEnumerable so that the collection will update when you add something to it or remove something from it.