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 and exposes the following properties:

  • Result—Gets or sets the DataGridColumn instance that will 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

The following examples show how to create a class that inherits from the DataGridCommand and add it to the Commands collection.

Create 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);                
    } 
} 

Add 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?