This is a migrated thread and some comments may be shown as answers.

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

1 Answer 107 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Milan
Top achievements
Rank 1
Milan asked on 10 Apr 2017, 03:13 PM

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

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 10 Apr 2017, 09:34 PM
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
Tags
DataGrid
Asked by
Milan
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or