locked
Integrate screen visual collection with existing records RRS feed

  • Question

  • We are implementing a 'load on demand' solution for a tree-view control (actually implemented using the ComponentOne FlexGrid).

    Initially the grid data source is populated using a query that load only root records.

    We are able to load related (child) records as needed (when expading a node) but we don't know if there is a way to put thoose 'post-loaded' records into the original visual collection. This is needed to maintain synchronization beetwen the selected item of the visual component and the selected item of visual collection (so any other visual element binded to the visual collection is updated accordingly).

    Please note that using <VisualCollection>.AddNew is not feeasable because added elements result as newòy created records (while the records are just loaded from the data source).

    Any idea?

    Thank you.


    Robin Poltronieri

    Friday, September 4, 2015 12:57 PM

All replies

  • Hi Robbin Poltronieri,

    What do you mean the "post-loaded"? And what mean of the "added elements result as newòy created records"? Do you mean you want to synchronize the data that added after display the tree-view?

    I think we can use a custom Silverlight control which use MVVM. In this custom control, we can define a dependency property which used to bind on the tree-view control. When there has new records added, please get the collection again and re-bind it to the tree-view control. The dependency will changes the UI automatically.

    If you don't want to use a custom control and don't want to use the <VisualCollection>.AddNew, I suggest you get the VisualCollection again. Then find the tree-view control and bind this collection to tree-view control.

    But I think the <VisualCollection>.AddNew is proper. As far as I know, LightSwitch is based on MVVM pattern. So when you add a new record with the <VisualCollection>.AddNew, it will display on screen immediately.

    If misunderstanding, please feel free to let me know.

    Best Regards,

    Weiwei

    Tuesday, September 8, 2015 11:58 AM
    Moderator
  • Hi Weiwei.

    Thank you for your answer.

    By 'post loaded' I mean the following:

    At initial screen load, only 'root' elements are loaded -> the tree-view shows only 1st level nodes. When a node is expanded, a query to the database is issued and only the children of the expanded node are loaded.

    By 'added elements result a newly added elements' I mean the following:

    When a node is expanded a query load records that where not part of the initial query -> the 'on-demand' loaded elements are not included in the visual collection populated by the screen query. The only way to include the last loaded records is to use the 'AddNew' method on the visual vollection but this method consider the added element as new element that must be 'created' on the database.

    Re-issuing the query doesn't works because the original query only include root level records. A solution could be to modify the query to include expanded nodes but this is not simple - actually two distinct queries are used:

     - a 'startup' query that loads root elements

     - an 'expansion' query that loads elements that are child of a specified (already loaded) element

    We are using a third party control (ComponentOne FlexGrid) that implements tree-view mode in a sort of trocky way. Rebinding the data source for every data load is not feasable for various reason, such a focus lost and performance issues when the node count became great.

    So, our approach should be:

     1. load root nodes using screen query (into visual collection)

     2. copy visual collection contents into new ObservableCollection OC; set OC as datasource for the UI element

     3. load child records on expand action using a separate query

     4. integrate child records into screen visual collection so other UI elements can 'see' the post-loaded records

     Point 4 is out issue.

    Thank you.


    Robin Poltronieri

    Wednesday, September 9, 2015 12:55 PM
  • Here's a picture that describe the screen structure and the problem of maintain sync between screen elements binded to the same data source



    Robin Poltronieri

    Wednesday, September 9, 2015 1:14 PM