🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
VCurrent and vSelected
This page was created by Hans.karlsen on 2020-07-17. Last edited by Wikiadmin on 2026-07-29.

You use vCurrent_ and vSelected_ variables in a cursored ViewModel to act on the row the user last focused and, when enabled, the rows the user selected in a grid.

What the variables represent

MDriven creates and maintains cursor variables for each level (nesting) in a ViewModel. The variables are strongly typed to the object type represented by that nesting. Their suffix identifies the nesting.

Variable Meaning When it is maintained
vCurrent_<NestingName> The object that the user most recently focused or clicked in the named nesting. For a cursored ViewModel nesting.
vSelected_<NestingName> A collection of objects selected in the named nesting. When the nesting uses Nesting.MultiSelect.

For example, if a nesting named Order displays orders, vCurrent_Order is the currently focused order. If that grid permits multiple selection, vSelected_Order contains the selected orders. Use the current variable when an action operates on one focused object; use the selected collection when an action operates on several rows.

Use the correct variable in an expression

Use these variables in ViewModel actions and in OCL expressions where you need the user's current focus or selection.

  1. Add the object list as a nesting in your ViewModel.
  2. Give the nesting a name that makes the cursor variable clear, such as Order.
  3. For a single-row action, use vCurrent_Order as the object the action should use.
  4. For a multi-row action, enable Nesting.MultiSelect and use vSelected_Order as the collection of selected objects.
  5. Open the OCL or Action Editor and inspect the available variables to verify the exact variable name and type for the current context.

For a concrete action example, an action labelled Process focused order should use vCurrent_Order. An action labelled Process selected orders should use vSelected_Order, so that it works on the collection chosen in the grid.

vCurrent is not self

vCurrent_<NestingName> identifies the active object for the named nesting across the ViewModel. In contrast, self depends on where the expression is evaluated: it is the object currently being rendered at that expression's location.

For example, while a ViewModel renders a list of Years, self in the Year nesting is the Year currently being rendered. vCurrent_Year is the one Year the user selected, regardless of which ViewModel nesting refers to it. Do not substitute vCurrent for self when defining a normal master-detail relationship; doing so can cause unnecessary tree expansion and updates. See How to use vCurrent and “self” correctly in viewmodels for the rendering implications and suitable patterns.

Root cursor

vCurrent_Root is the generic name for the vCurrent_<ViewModel> variable at the root level. In a rooted ViewModel that represents one object, its root current object can be the same object as self.

Configure multi-selection

Set Nesting.MultiSelect on a table or grid nesting when users must select more than one row. MDriven then maintains the corresponding vSelected_ collection.

Without multi-selection, design actions around vCurrent_. A current row is the focused row; it is not a substitute for a deliberate multi-row selection.

Control first-row selection in WebUI DataGrids

In WebUI DataGrids, first-row selection depends on whether the nesting allows multiple selection.

Grid configuration Default AutoSelectFirstRow behavior
Nesting.MultiSelect is not set The first row is automatically selected.
Nesting.MultiSelect is set The first row is not automatically selected.

Override either default by explicitly setting Nesting.AutoSelectFirstRow:

  • Set it to true when the grid should focus the first available row when it opens.
  • Set it to false when no row should be automatically focused.

For example, set Nesting.AutoSelectFirstRow to true on a multi-select order grid if an order-detail area must show an initial focused order. Set it to false when the user must make the first choice explicitly.

See Tables and Grids for grid-related configuration.

Turnkey selection behavior

In Turnkey clients, focused state and checkbox-based selection must be handled as distinct concepts. A row can be in vSelected_ because it was current, even though the user did not check its selection box. When that row stops being current, it may need to be removed from vSelected_ if being current was its only reason for inclusion.

This distinction differs from WPF controls, where focused and selected states have a natural separation and controls include the focused item in the selected collection. In web grids, the separate selection checkbox means the framework must distinguish selection caused by the checkbox from selection associated with the current row.

When designing a Turnkey action, therefore, choose the variable that reflects the intent:

  • Use vCurrent_ for an operation on the focused row.
  • Use vSelected_ only for an operation that is intended to use the grid's maintained selected collection.

Related variables

These cursor variables are part of the predefined ViewModel-variable set. Built in ViewModel variables lists other variables, including client viewport and device variables. For the full context of predefined variables, custom variables, and contexts where cursor variables are not normally used, see ViewModel variables.

See also