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

Text Column

A DataGridTextColumn converts the content of each associated cell to a System.String object. The DataGridTextColumn provides better performance than a DataGridTemplateColumn.

Key Properties

The Text column provides the CellContentFormat key feature, which gets or sets the custom format for each cell value. The Text column uses the String.Format routine and the format you pass has to be in the form required by this method.

Example

The following example shows how to generate a DataGridTextColumn manually.

  1. First, create the business object.

    Create the Data Model

        public class Data 
        { 
            public string Country { get; set; } 
            public string Capital { get; set; } 
        } 
    
  2. The next step is to create some sample data.

    Create the Sample Data

        public MainPage() 
        { 
            this.InitializeComponent();      
            this.DataContext = new List<Data> 
            { 
                new Data { Country = "Columbia", Capital = "Bogota"}, 
                new Data { Country = "Germany", Capital = "Berlin"}, 
                new Data { Country = "Italy", Capital = "Rome"}, 
                new Data { Country = "France", Capital = "Paris" }, 
                new Data { Country = "Bulgaria", Capital = "Sofia" }, 
            }; 
        } 
    
  3. This example shows two columns. As you can see, it uses the CellContentStyle property to apply a style to the first column and the CellContentFormat property to format the content of the second column. The example also uses the PropertyName property to associate each column with the relevant property from the model.

    Define in XAML

        <telerikGrid:RadDataGrid UserEditMode="Inline" x:Name="grid" AutoGenerateColumns="False" ItemsSource="{Binding}" VerticalAlignment="Center" Width="300"> 
            <telerikGrid:RadDataGrid.Columns> 
                <telerikGrid:DataGridTextColumn PropertyName="Country" Header="Country"> 
                    <telerikGrid:DataGridTextColumn.CellContentStyle> 
                        <Style TargetType="TextBlock"> 
                            <Setter Property="Foreground" Value="Red"/> 
                            <Setter Property="FontStyle" Value="Italic"/> 
                            <Setter Property="HorizontalAlignment" Value="Center"/> 
                            <Setter Property="VerticalAlignment" Value="Center"/> 
                        </Style> 
                    </telerikGrid:DataGridTextColumn.CellContentStyle> 
                </telerikGrid:DataGridTextColumn> 
                <telerikGrid:DataGridTextColumn PropertyName="Capital" Header="Capital" CellContentFormat="{}{0} city"/> 
            </telerikGrid:RadDataGrid.Columns> 
        </telerikGrid:RadDataGrid> 
    
    Text Column

WinUI Text Column Style And Format

In this article
Not finding the help you need?