Data Grid Command API
- 4 minutes to read
You can maintain a clean MVVM pattern and define custom logic in a ViewModel. The GridControl includes the following command counterparts for events that expect a return value:
Property | Description |
---|---|
Grid |
Gets or sets a command that is executed before a new row is added to the Grid |
Table |
Gets or sets a command that allows you to specify custom cell merge rules. |
Grid |
Gets or sets a command executed when a cell value is changed. |
Grid |
Gets or sets a command executed when a user edits a cell value (for example, types or deletes a character, chooses a value from the drop-down list). |
Grid |
Gets or sets a command that customizes a data cell‘s display text. |
Custom |
Gets or sets a command that applies custom rules to group rows. |
Grid |
Gets or sets a command that uses custom rules to sort rows. |
Custom |
Gets or sets a command that displays custom text in group rows. |
Grid |
Gets or sets a command that uses custom rules to filter rows. |
Grid |
Gets or sets a command that calculates a custom summary. |
Custom |
Gets or sets a command that specifies which summaries should be calculated and displayed. |
Grid |
Gets or sets a command that populates unbound columns with data. |
Custom |
Gets or sets a command that populates a column’s Drop-down Filter with unique values. |
Table |
Gets or sets a command that allows you to initialize a new row with default values. |
Grid |
Gets or sets a command that is executed when a row fails validation or cannot be saved to a data source. |
Node |
Gets or sets a command that is executed when a node’s property changes. |
Grid |
Gets or sets a command that is executed when the changes made in a row are discarded. |
Table |
Gets or sets a command executed when a user double-clicks a row. |
Grid |
Gets or sets a command executed when the Grid |
Grid |
Gets or sets a command that allows you to validate the focused cell’s data. |
Grid |
Gets or sets a command that validates row values. |
These commands expose UI-independent arguments and pass them to the ViewModel as a typed parameter. As a result, you can modify the command parameter at the ViewModel level and return values to a View:
<dxg:GridControl CustomColumnDisplayTextCommand="{Binding CalculateDisplayTextCommand}" />
public class ViewModel: ViewModelBase {
// ...
[Command]
public void CalculateDisplayText(DevExpress.Mvvm.Xpf.CustomColumnDisplayTextArgs args) {
args.DisplayText = GetLocalizedValue(args.FieldName, args.Value, Language);
}
}
If an event does not have a command counterpart property, you can use the EventToCommand behavior to bind your command to the event. This behavior allows you to pass a parameter to the bound command and return the parameter to the event.
Note
Command counterparts for events do not support Asynchronous Commands.
#Built-in Commands
The GridControl includes multiple built-in commands that allow you to expand/collapse group rows, move focus, sort/group data, and so on.
The following classes store these commands:
Class | Description |
---|---|
Grid |
Provides access to built-in grid commands. |
Data |
Contains built-in commands common to all the Grid |
Table |
Provides access to the Table |
Tree |
Provides access to the Tree |
Card |
Provides access to the Card |
Refer to these class members to get the full list of available commands.
The code snippet below demonstrates how to use built-in commands:
<Button Command="{Binding ElementName=grid,Path=View.Commands.ShowSearchPanel}" />
#Custom Commands
You can specify your own commands in a ViewModel. The following help topic illustrates how to create a command that deletes selected rows from the GridControl: Binding to a Collection of Selected Items.