Row behaviors
RadGridView manages user mouse and keyboard input over its rows by GridRowBehavior. Depending on the row type, RadGridView introduces different behaviors, listed on the table below:
Row behavior | Row type |
---|---|
GridDataRowBehavior | GridViewDataRowInfo |
GridHierarchyRowBehavior | GridViewHierarchyRowInfo |
GridNewRowBehavior | GridViewNewRowInfo |
GridGroupRowBehavior | GridViewGroupRowInfo |
GridFilterRowBehavior | GridViewFilteringRowInfo |
GridHeaderRowBehavior | GridViewTableHeaderRowInfo |
GridDetailViewRowBehavior | GridViewDetailsRowInfo |
By implementing a specific custom row behavior, developers can change the default row functionality or supplement the existing one.
Let’s start with constructing a hierarchical RadGridView and populate it with data.
By default, when the user hits the Delete key over a certain row, the row is deleted. We will extend this functionality by notifying the user when he tries to delete a parent row, which ChildRows collection is not empty. For this purpose, it is necessary to create a custom grid behavior. To do this, create a new class named CustomGridHierarchyRowBehavior. As we are currently using a hierarchical grid, our class should inherit the GridHierarchyRowBehavior. Override the ProcessDeleteKey method in order to display a MessageBox and proceed with the delete operation after confirmation only:
Next we will register this behavior in our grid. Add the following code after populating the grid with data:
The next modification we are going to introduce is to override the OnMouseDownLeft method and show the context menu for the GridCheckBoxCellElement, associated with the mouse location. First, it is necessary to use the grid navigator to process selection of the cell element, positioned at the mouse location. Afterwards, show the context menu for the specific cell:
RadGridView supports rows/cells navigation by default, using the arrow keys. It is possible to customize this behavior as well. In the CustomGridHierarchyRowBehavior class override the ProcessKey method and stop the base grid logic for navigation upwards/downwards if the current row belongs to the MasterTemplate and its “IsActive” cell value is set to false:
Following the demonstrated approach, developers can customize not only the hierarchy rows, but the new row for example, implementing a custom GridNewRowBehavior and registering it for the GridViewNewRowInfo.