Skip to main content
A newer version of this page is available. .

Implementation of Typed Method Delegates

  • 10 minutes to read

A call to a grid view model’s GridViewModel.ProcessCustomBinding method in a Controller delegates the implementation of a grid view model population to Model-layer functions specified via the method’s typed parameters. In general, the ProcessCustomBinding method can accept five parameters that point to method delegates of specific types. This topic describes the available delegate types and provides you with information on how they can be implemented.

You can refer to the following demos to see how two binding scenarios (simple and advanced) are implemented using different method delegates.

You can also make use of the following code samples to start implementing your custom binding scenario.

GridViewCustomBindingGetDataRowCountHandler

Method implementation is required.

Always implement this method to return the total number of data rows within your model, taking into account the applied filtering (if any).

This method accepts the e parameter of the GridViewCustomBindingGetDataRowCountArgs type, which provides you with the following arguments.

Name Property Description
DataRowCount GridViewCustomBindingGetDataRowCountArgs.DataRowCount Gets or sets the total number of data rows within a custom model, taking into account the filtering applied within the grid (if any).
FilterExpression GridViewCustomBindingArgsBase.FilterExpression Gets the filter condition currently applied to the GridView (if any filtering is used).
State GridViewCustomBindingArgsBase.State Gets an object containing information about the current state on the GridView.

When implementing this delegate, obtain the total number of rows in your model and assign it to the GridViewCustomBindingGetDataRowCountArgs.DataRowCount property. The GridView requires this information to properly calculate the number of grid pages to be displayed within the pager.

The returned total number should depend upon the filtering conditions (if they were applied to the grid). Use the GridViewCustomBindingArgsBase.FilterExpression property to obtain the grid’s filter expression and apply it to your model to obtain the proper number of rows that meet the filter. If no filtering is applied, the GridViewCustomBindingArgsBase.FilterExpression property returns an empty string.

The common procedure for implementation of this delegate is provided below:

  • Filter your model (if filtering is used) using e.FilterExpression.
  • Obtain the model’s total row count and return it to e.DataRowCount.

In a general case, the implementation will look as follows.


public static void MyGetDataRowCount(GridViewCustomBindingGetDataRowCountArgs e) {
            e.DataRowCount = Model
                .ApplyFilter(e.FilterExpression) //Your function that applies a filter to your model
                .Count(); //Return the total count of data rows in your model (taking into account the applied filtering, if any)
        }

GridViewCustomBindingGetDataHandler

Method implementation is required.

Always implement this method to populate the grid view model with data rows requested by the grid.

This method accepts the e parameter of the GridViewCustomBindingGetDataArgs type, which provides you with the following arguments.

Name Property Description
Data GridViewCustomBindingDataArgsBase.Data Gets or sets a list of currently requested model characteristics (depending upon which delegated method is being implemented, it can be a list of data rows, or a list of grouping information objects, or a list of calculated summary values).
DataRowCount GridViewCustomBindingGetDataArgs.DataRowCount Gets the number of currently requested data rows to return.
GroupInfoList GridViewCustomBindingDataArgsBase.GroupInfoList Gets a list of objects containing information about the group rows (in particular, the field name identifying the corresponding grouped column, the group value - key, and the number of data rows within the group - count).
StartDataRowIndex GridViewCustomBindingGetDataArgs.StartDataRowIndex Gets the index of the first row in the requested row list.
State GridViewCustomBindingArgsBase.State Gets an object containing information about the current state on the GridView.

When implementing this delegate, return the requested data rows via the GridViewCustomBindingDataArgsBase.Data property.

The common procedure for the implementation of this delegate is provided below:

  • Filter your model (if filtering is used) using e.State.FilterExpression.
  • Filter your model based on the applied grouping (if grouping is used) by using e.GroupInfoList.
  • Sort your model (if sorting or grouping is used) using e.State.SortedColumns.
  • Obtain the number of rows specified by the e.DataRowCount starting from e.StartDataRowIndex, and return the obtained row list to e.Data.

In a general case, the implementation will look as follows.


public static void MyGetData(GridViewCustomBindingGetDataArgs e) {
            e.Data = Model
                .ApplyFilter(e.State.FilterExpression) //Your function that filters your model
                .ApplyGroupFilter(e.GroupInfoList) //Your function that filters your model so that it contains rows meeting the applied grouping
                .ApplySorting(e.State.SortedColumns) //Your function that sorts your model
                .Skip(e.StartDataRowIndex) //Position on the first required data row
                .Take(e.DataRowCount); //Get the number of currently requested data rows (rows of the current page or visible rows of the processed group)
        }

GridViewCustomBindingGetSummaryValuesHandler

Method implementation is optional. It is required if you use summaries within the grid.

Provide implementation for this method to calculate and return values of summaries required within the grid, taking into account the applied filtering (if any).

This method accepts the e parameter of the GridViewCustomBindingGetSummaryValuesArgs type, which provides you with the following arguments.

Name Property Description
Data GridViewCustomBindingDataArgsBase.Data Gets or sets a list of currently requested model characteristics (depending upon which delegated method is being implemented, it can be a list of data rows, or a list of grouping information objects, or a list of calculated summary values).
FilterExpression GridViewCustomBindingArgsBase.FilterExpression Gets the filter condition currently applied to the GridView (if any filtering is used).
GroupInfoList GridViewCustomBindingDataArgsBase.GroupInfoList Gets a list of objects containing information about the group rows (in particular, the field name identifying the corresponding grouped column, the group value - key, and the number of data rows within the group - count).
State GridViewCustomBindingArgsBase.State Gets an object containing information about the current state on the GridView.
SummaryItems GridViewCustomBindingGetSummaryValuesArgs.SummaryItems Gets a list of summary items which are used within the GridView and whose values must be calculated.

When implementing this delegate, calculate values for summaries from the GridViewCustomBindingGetSummaryValuesArgs.SummaryItems collection, put the calculated summary values in a list, and return this list via the GridViewCustomBindingDataArgsBase.Data property.

The common procedure for the implementation of this delegate is provided below:

  • Filter your model (if filtering is used) using e.State.FilterExpression.
  • Filter your model based on the applied grouping (if grouping is used) using e.GroupInfoList.
  • Traverse the e.SummaryItems list, calculate a summary value for each summary item, and return a list of the calculated values to e.Data.

In a general case, the implementation will look as follows.


public static void MyGetSummaryValues(GridViewCustomBindingGetSummaryValuesArgs e) {
            var query = Model
                .ApplyFilter(e.State.FilterExpression) //Your function that filters your model
                .ApplyGroupFilter(e.GroupInfoList); //Your function that filters your model so that it contains rows meeting the applied grouping
            var list = new ArrayList();
            foreach(var item in e.SummaryItems) {
                switch(item.SummaryType) {
                    case SummaryItemType.Count:
                        list.Add(query.Count());
                        break;
                    case SummaryItemType.Sum:
                        list.Add(query.Sum(item.FieldName));
                        break;
                }
            }
            e.Data = list;
        }

GridViewCustomBindingGetGroupingInfoHandler

Method implementation is optional. It is required if you use grouping within the grid.

Provide implementation for this method to return grouping information for group rows (the group value - key, and the number of data rows within the group - count) related to the grouped column. And also take into account the applied filtering (if any).

This method accepts the e parameter of the GridViewCustomBindingGetGroupingInfoArgs type, which provides you with the following arguments.

Name Property Description
Data GridViewCustomBindingGetGroupingInfoArgs.Data Gets or sets a list that contains grouping information (the group value - key, and the number of data rows within the group - count) on group rows.
FieldName GridViewCustomBindingGetGroupingInfoArgs.FieldName Gets the name of a data field against whose values the currently processed grouping operation is being performed.
GroupInfoList GridViewCustomBindingDataArgsBase.GroupInfoList Gets a list of objects containing information about the group rows (in particular, the field name identifying the corresponding grouped column, the group value - key, and the number of data rows within the group - count).
SortOrder GridViewCustomBindingGetGroupingInfoArgs.SortOrder Gets the sort order to be applied to values of a data field specified by the GridViewCustomBindingGetGroupingInfoArgs.FieldName property when processing the current grouping operation.
State GridViewCustomBindingArgsBase.State Gets an object containing information about the current state on the GridView.

When implementing this delegate, create a list of GridViewGroupInfo objects that contain information about groups. The currently processed column, against which values a grouping operation is being performed, can be identified using the GridViewCustomBindingGetGroupingInfoArgs.FieldName property. For each created group, it is necessary to determine the group’s group value (key - GridViewGroupInfo.KeyValue) and the number of data rows within the group (count - GridViewGroupInfo.DataRowCount). The created list should be returned to the GridViewCustomBindingDataArgsBase.Data property.

The common procedure for the implementation of this delegate implementation is provided below:

  • Filter your model (if filtering is used) using e.State.FilterExpression.
  • Filter your model based on the applied grouping by using e.GroupInfoList.
  • Group your model based on values of the processed column using the e.FieldName.
  • Sort your model in the required order using e.SortOrder.
  • Form a list that contains grouping information (the group value - key, and the number of data rows within the group - count) on group rows.
  • Return the created list to e.Data.

In a general case, the implementation will look as follows.


public static void MyGetGroupingInfo(GridViewCustomBindingGetGroupingInfoArgs e) {
            e.Data = Model
                .ApplyFilter(e.State.FilterExpression) //Your function that filters your model
                .ApplyGroupFilter(e.GroupInfoList) //Your function that filters your model so that it contains rows meeting the applied grouping
                .GroupBy(e.FieldName) //Your function that groups your model based on values of the processed column
                .OrderBy(e.SortOrder)) //Your function that sorts your model in the required direction
                .GetGroupInfo(e.FieldName, e.SortOrder); //Your function that returns grouping information for group rows (the group value - key, and the number of data rows within the group - count) related to the processed group operation
        }

GridViewCustomBindingGetUniqueHeaderFilterValuesHandler

Method implementation is optional. It is required if you display header filter buttons to use filtering within the grid.

Provide implementation for this method to return unique values to be displayed in the header filter dropdown list invoked for a column.

This method accepts the e parameter of the GridViewCustomBindingGetUniqueHeaderFilterValuesArgs type, which provides you with the following arguments.

Name Property Description
Data GridViewCustomBindingGetUniqueHeaderFilterValuesArgs.Data Gets or sets a list of unique values contained within a specific data field.
FieldName GridViewCustomBindingGetUniqueHeaderFilterValuesArgs.FieldName Gets the name of the data field whose unique values should be returned.
FilterExpression GridViewCustomBindingArgsBase.FilterExpression Gets the filter condition currently applied to the GridView (if any filtering is used).
State GridViewCustomBindingArgsBase.State Gets an object containing information about the current state on the GridView.

When implementing this delegate, return a list of unique values obtained from a model data field (specified by the GridViewCustomBindingGetUniqueHeaderFilterValuesArgs.FieldName property) to the GridViewCustomBindingDataArgsBase.Data property. You may also need to take into account the applied filter condition, which can be obtained via the e.FilterExpression (GridViewCustomBindingArgsBase.FilterExpression) or e.State.FilterExpression.

The common procedure for implementation of this delegate is provided below:

  • Filter your model (if filtering is used) using e.FilterExpression.
  • Obtain a list of unique values from a data field specified by e.FieldName and return this list to e.Data.

In a general case, the implementation will look as follows.


public static void MyGetUniqueHeaderFilterValues(GridViewCustomBindingGetUniqueHeaderFilterValuesArgs e) {
            e.Data = Model
                .ApplyFilter(e.FilterExpression) //Your function that filters your model
                .GetUniqueValues(e.FieldName); //Your function that obtains unique values of the specified data field
        }
See Also