Creating custom cells
Custom data cell example
RadGridView provides a variety of visual cells (all inheriting from GridCellElement) with different functionality and purpose – header cells, indent cells, command cells, summary cells, group content cells, data cells, etc. All these cover the standard cases of the control usage. In case you need to implement more specific and custom scenario, you can create a custom cell. RadGridView provides powerful and flexible mechanism for creating cell types with custom content elements, functionality and properties.
You can use the following approach to create a custom data cell with a progress bar in it:
1. Create a class for the cell which derives from GridDataCellElement:
2. Create the RadProgressBarElement and add it as a child of the custom cell.You can achieve this by overriding the CreateChildElements method:
3. Override the SetContentCore method to update the progress bar according to the cell value:
4. The custom cell will have no styles, because there are no defined styles for its type in the themes. You can apply the GridDataCellElement’s styles to it by defining its ThemeEffectiveType:
5. Thanks to the UI virtualization mechanism only the currently visible cells are created and they are further reused when needed. A cell element is reused in other rows or columns if it is compatible for them. You can create a custom column and define that the custom cell IsCompatible for that column only. This will prevent the cell from being unintentionally reused by other columns.
6. Lastly, we need to add the custom column to our grid. The following code snippet demonstrates the usage of the custom column:
Figure 1: The custom column is now added to the grid.
Extending the custom data cell example
You can extend the custom cell further by adding a button in it and subscribing to its Click event. The button will be used to restart the progress bar by setting the cell value to 0. You can achieve this by using the following approach:
1. Initialize and add the elements to the cell:
2. Override the ArrangeOverride method to arrange the children elements of the cell:
Figure 2: The new custom cell is shown in RadgridView.
Custom group cell example
When the EnableGrouping property is set to true the GroupPanelElement is displayed at the top of the grid. Thus, when the user drags a column and drops it onto the panel GridGroupContentCellElements are created for the group rows. The following example demonstrates a sample approach how to customize the GridGroupContentCellElement in order to add a drop-down with aggregate functions next to the group header and calculate the function considering the user selection
Figure 3: The custom group cell contains a drop down list.
1. Create a class that inherits the GridGroupContentCellElement. In its CreateChildElements method we will use a RadDropDownListElement which contains the aggregate functions and a LightVisualElement to display the calculated result. In the SetContent method we should display the cell information considering for which row it is currently being used:
2. Subscribe to the CreateCell event where we should replace the default GridGroupContentCellElement with the custom one: