Edit this page

Implementation

Fast and quite easy approach for implementing the built-in commands in RadGridView is to set them directly to a particular RadButton. Thus, once you click a single button, the predefined command will be executed.

Basically, there are two main scenarios to define a button - inside and outside the RadGridView. In the first case, you may define it as a CellTemplate of a particular column for example. It will result in a separate RadButton in each row and the command to be executed will be applied to the corresponding item. The definition will be as follows:

XAML

<telerik:GridViewColumn>
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate>
            <telerik:RadButton Content="Delete" Command="telerik:RadGridViewCommands.Delete" CommandParameter="{Binding}" />
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

Once the source object is defined up in the tree as a DataContext, you may set the source for the CommandParameter Property's Binding to be the entire object.

The other approach will be to define the RadButton beyond the boundaries of RadGridView:

XAML

<telerik:RadButton Width="150" Content="Save insert/edit" 
           Command="telerik:RadGridViewCommands.CommitEdit" 
           CommandTarget="{Binding ElementName=RadGridView1}" />

In this case the target object needs to be explicitly set in the definition of the CommandTarget Property, specifying the RadGridView towards which the command has to be applied. This specific command will be automatically disabled untill a change in any of the items in the grid is made.