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

Quick and (Hopefully) easy question about CellDataTemplates

3 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 24 Apr 2017, 12:53 PM

Hello All,

     I have a quick and easy question about setting up a cell datatemplate.  I have a class that has two properties: a boolean value and a string value.  In my app, I have created a collection of this class and would like to display it in a grid.  I would like to display the boolean value as either a check-mark or a x-mark as in the example image I've attached...  I'm pretty sure this can and should be done as a celldatatemplate, but I have no idea as to where to start...  Could someone please point me in the right direction???  Is there a good example of this or is there a good explanation of setting a template up somewhere out there???

 

Thanks in advance,

 

Kevin Orcutt

 

 

3 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 1
answered on 25 Apr 2017, 02:24 PM

Well,

I haven't found much...  The one thing that I thought might work didn't...  I tried this:

<telerik:RadGridView
    Grid.Row="1"
    Grid.ColumnSpan="2"
    Margin="5,5,4.556,5"
    AutoGenerateColumns="False"
    ItemsSource="{Binding SaveResults}"
    RowIndicatorVisibility="Collapsed"
    ShowGroupPanel="False">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn
            DataMemberBinding="{Binding Status}"
            Header="Status"
            IsFilterable="False"
            IsReadOnly="True">
            <telerik:GridViewDataColumn.CellTemplateSelector>
                <telerik:ConditionalDataTemplateSelector>
                    <telerik:DataTemplateRule Condition="Status == true">
                        <DataTemplate>
                            <Image Source="/Images/Check.png" />
                        </DataTemplate>
                    </telerik:DataTemplateRule>
                    <telerik:DataTemplateRule Condition="Status == false">
                        <DataTemplate>
                            <Image Source="/Images/X_Mark.png" />
                        </DataTemplate>
                    </telerik:DataTemplateRule>
                </telerik:ConditionalDataTemplateSelector>
            </telerik:GridViewDataColumn.CellTemplateSelector>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn
            Width="*"
            DataMemberBinding="{Binding StatusLine}"
            Header="Result"
            IsFilterable="False" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

 

Any other ides????  This is getting a little frustrating!

Thanks in advance,

 

Kevin

 

0
Heiko
Top achievements
Rank 1
answered on 26 Apr 2017, 04:47 PM

Maybe you should try

Condition="Status = true" instead of 

Condition="Status == true"

And a little hint besides that: just try to use the new Font Glyphs by Telerik (http://docs.telerik.com/devtools/wpf/styling-and-appearance/glyphs/common-styles-appearance-glyphs-overview) so you don't need to put an image in the template but just a Textblock. That's the way I use it.

hth
Heiko

0
Stefan
Telerik team
answered on 27 Apr 2017, 05:58 AM
Hello guys,

Another possible approach for satisfying such requirement would be to use the CellTemplateSelector mechanism provided by GridViewColumn. You may also find the Template Selectors section of RadGRidView's WPF Demos useful, or their online equivalents.

All the best,
Stefan X1
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Kevin
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 1
Heiko
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or