Change displaying text in Datagrid

3 posts, 1 answers
  1. Stavros
    Stavros avatar
    18 posts
    Member since:
    Oct 2017

    Posted 29 May 2018 Link to this post

    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. Answer
    Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1168 posts

    Posted 29 May 2018 Link to this post

    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
  3. Stavros
    Stavros avatar
    18 posts
    Member since:
    Oct 2017

    Posted 30 May 2018 Link to this post

    Thank you, Lance!! I solve my problem! 
Back to Top