Customize Cell Content
This article demonstrates how to add a column with a delete button for each row. We will benefit from the static RadGridViewCommands class to automatically delete the corresponding row item upon clicking the button. Figure 1 illustrates the desired result.
Figure 1: RadGridView with custom button column
There are several ways to achieve this. Let's look at some of them.
Create a Custom Column
This approach involves inheriting from GridViewColumn and overriding the CreateCellElement method. In this method, you can create the button (if it has not already been created) and set its properties as demonstrated in Example 1.
In order to automatically export a custom column, it should implement the IExportableColumn interface.
Example 1: Override the CreateCellElement method
Now you need to add this custom column to our RadGridView's Columns collection. Example 2 shows how to do this in XAML.
Example 2: Define the custom column in XAML
The same can be achieved in code-behind as illustrated in Example 3.
Example 3: Define the custom column in code-behind
Use the GridViewColumn's CellTemplate Property
With this approach we will re-define the template of the cells for that column. In this case, we specify a simple DataTemplate which contains our delete button.
Specify the GridViewColumn's CellTemplate
Notice that we've set the Command of the button to the RadGridViewCommands.Delete command and passed in the current row item (the DataContext of the cell) as the CommandParameter.