[C#][UWP] How to display text instead of checkboxes in DataGridBooleanColumn

2 posts, 0 answers
  1. Milan
    Milan avatar
    12 posts
    Member since:
    Mar 2016

    Posted 10 Apr Link to this post

    Hi Team,

    I have a RadDataGrid, wherein, I have multiple autogenerated columns and I want to display "yes/no" text in DataGridBooleanColumn but I could not find any way to do so.

    Could you please help me to achieve this scenario?

    Regards

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    419 posts

    Posted 10 Apr Link to this post

    Hello Milan,

    For this, you need to use a TemplateColumn with a TextBlock.

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.Resources>
                <local:BoolToYesNoConverter x:Key="BoolToYesNoConverter"/>
            </Grid.Resources>
             
            <grid:RadDataGrid>
                <grid:RadDataGrid.Columns>
                    <grid:DataGridTemplateColumn Header="Country">
                        <grid:DataGridTemplateColumn.CellContentTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding MyBoolProperty, Converter={StaticResource BoolToYesNoConverter}}" />
                            </DataTemplate>
                        </grid:DataGridTemplateColumn.CellContentTemplate>
                    </grid:DataGridTemplateColumn>
                </grid:RadDataGrid.Columns>
            </grid:RadDataGrid>
        </Grid>



    Note that if your bound object is a bool, then you'll also need to use a converter to return the string values of "Yes" and "No"

    For example:

    class BoolToYesNoConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, string language)
            {
                return (bool) value ? "Yes" : "No";
            }
     
            public object ConvertBack(object value, Type targetType, object parameter, string language)
            {
                throw new NotImplementedException();
            }
        }

    You can find more information about column types and properties here.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top