New to Telerik UI for WinUI? Download free 30-day trial

GenerateColumn Command

The GenerateColumn command provides a way to customize the logic for the automatic generation of grid columns. The default implementation will generate a DataGridTextColumn instance for each of the public properties in the underlying data item.

Execution Parameter

The execution parameter is of type GenerateColumnContext, which exposes the following properties:

  • Result: Gets or sets the DataGridColumn instance that should be associated with the specified property. If no instance is provided (null), the current property will be skipped and no column will be associated with it.
  • PropertyName: Gets the name of the property for which a column instance is needed.

Custom GenerateColumn Command

Examples 1 and 2 show how to create a class that inherits from DataGridCommand and add it to the Commands collection.

Example 1: Creating a custom GenerateColumn Command

public class CustomGenerateColumnCommand : DataGridCommand 
{ 
    public CustomGenerateColumnCommand() 
    { 
        this.Id = CommandId.GenerateColumn; 
    } 
 
    public override bool CanExecute(object parameter) 
    { 
        var context = parameter as GenerateColumnContext; 
        // put your custom logic here 
        return true; 
    } 
 
    public override void Execute(object parameter) 
    { 
        var context = parameter as GenerateColumnContext; 
        // put your custom logic here 
 
        this.Owner.CommandService.ExecuteDefaultCommand(CommandId.GenerateColumn, context);                
    } 
} 

Example 2: Adding the custom Command to the Commands collection

<Grid xmlns:grid="using:Telerik.UI.Xaml.Controls.Grid"> 
    <grid:RadDataGrid Width="600" Height="460" x:Name="grid" Hold> 
        <grid:RadDataGrid.Commands> 
            <local:CustomGenerateColumnCommand/> 
        </grid:RadDataGrid.Commands> 
    </grid:RadDataGrid> 
</Grid> 

See Also

In this article
Not finding the help you need?