locked
Returning a view based on a selection in a grid (another view) RRS feed

  • Question

  • Hi,

    I have a view that I am displaying in a DataGrid (View1-Grid1). On selection of a row in the View1-Grid1 (or by default, for the first row in the grid), I wan't to populate another grid in a tab (underneath View1-Grid1) which is based on a another view (View2 - Grid2). The views are related by a common field. How do I set this up in lightSwitch? I can't seem to establish a relationship between the views - Is there a way to do this in code?

    Thanks in advance

    Mike

    Sunday, September 12, 2010 12:14 PM

Answers

  • I'm assuming that View1 and View2 are visual collections that are a part of the screen (they show up as collections in the screen members list on the left side of the Screen Designer).

    You'll want to create a query based on View2 (in the Screen Designer, click the Edit Query link next to View2) that takes a parameter that is of the type of the field that View1 and View2 share.  Then add a filter expression to the query that uses the parameter to constrain the results of the query.  Then, in the Screen Designer, you'll bind the parameter to the related field of the SelectedItem property of View1.  Select the parameter that you just created on the query, go the property sheet, and change the Parameter Value property to be something like View1.SelectedItem.<CommonField> where <CommonField> is the field on View1 that is common to both View1 and View2.

    When you then run the application, Grid2 should only show entities that are related to the selected entity in Grid1.

    I can provide a more specific example, if you'd like, instead of talking in generic terms if the above is too vague.

    Thursday, September 16, 2010 7:50 AM