This is a migrated thread and some comments may be shown as answers.
Change displaying text in Datagrid
2 Answers 14 Views
This is a migrated thread and some comments may be shown as answers.
Stavros
Top achievements
Rank 1
Stavros asked on 29 May 2018, 08:39 AM

Hi, I want to change the text that appears in DataGridBooleanColumn . I don't want to display True or False but something else like Yes, No, Oui, Non etc. 

Also is there any way to change an int field like having binding an Id from another table but wanting to display the name?

Thanks,
Stavros 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 29 May 2018, 05:32 PM
Hi Stavros,

You can accomplish this by using a DataGridTemplateColumn instead of a BooleanColumn. In the DataTemplate, use a Label to display the text. Bind that Label's Text property to the model's boolean property and use a converter to return the exact text you want to display.

For example:

<!-- In the resources -->
<converters:MyBoolToStringConverter x:Key="MyConverter" />
 
<!-- In the DataGrid's Columns collection -->
<telerikGrid:DataGridTemplateColumn HeaderText="Template Column">
    <telerikGrid:DataGridTemplateColumn.CellContentTemplate>
        <DataTemplate>
            <Label Text="{Binding MyBoolProperty, Converter={StaticResource MyConverter}" />
        </DataTemplate>
    </telerikGrid:DataGridTemplateColumn.CellContentTemplate>
</telerikGrid:DataGridTemplateColumn>

And the converter can be something like this:

public class MyBoolToStringConverter : IValueConverter
{
    public void Convert(object value, ....)
    {
        return (bool)value ? "Oui" : "Non";
    }
....
}

Note that the code above was abbreviated so that I could focus on the logic pertaining to changing the display text. If you're not familiar with IValueConverter, here's a tutorial from Xamarin that explains how they work with the rest of the required code.

Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
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
0
Stavros
Top achievements
Rank 1
answered on 30 May 2018, 07:15 AM
Thank you, Lance!! I solve my problem! 
Asked by
Stavros
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Stavros
Top achievements
Rank 1
Share this question
or