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

RadGridView and a TempalteSelector

1 Answer 98 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tory
Top achievements
Rank 1
Tory asked on 05 Oct 2012, 04:07 PM
What is the proper way to use a template selector for RadGridView? Templates are currently not being selected and my SelectTemplate method in DetailsTemplateSelector is not being called. I'm using this currently:

<telerik:RadGridView.RowDetailsTemplate>
                <DataTemplate>
                    <ItemsControl
                           ItemTemplateSelector="{StaticResource detailsTemplateSelector}"
                           />
                </DataTemplate>
            </telerik:RadGridView.RowDetailsTemplate>

Resources:

<Window.Resources>
        <DataTemplate x:Key="theBasicView">
            <controls:InfoDetailsControl InfoDetail="{Binding InfoDetails}" />
        </DataTemplate>


        <DataTemplate x:Key="theTableView">
            <telerik:RadGridView ItemsSource="{Binding DetailsTable}"
                                         ShowGroupPanel="False"
                                         AutoGenerateColumns="True"
                                         ColumnBackground="Beige"
                                         RowIndicatorVisibility="Hidden"
                                         AlternationCount="2"
                                         />
        </DataTemplate>


        <analysis:DetailsTemplateSelector 
            BasicView="{StaticResource theBasicView}"
            TableView="{StaticResource theTableView}"
            x:Key="detailsTemplateSelector"
            />
    </Window.Resources>

Code behind:

public class DetailsTemplateSelector : DataTemplateSelector
    {
        public DataTemplate BasicView { get; set; }
        public DataTemplate TableView { get; set; }


        public override DataTemplate SelectTemplate(object item, DependencyObject container) {
            FrameworkElement element = container as FrameworkElement;
            if (element != null && item != null && item is ViewableRuleResult)
            {
                ViewableRuleResult ruleResult = item as ViewableRuleResult;
                Window window = Application.Current.MainWindow;


                if (ruleResult.DetailsTable == null)
                {
                    return BasicView;
                }
                else
                {
                    return TableView;
                }             
            }
            return null;
        }
    }

1 Answer, 1 is accepted

Sort by
0
Tory
Top achievements
Rank 1
answered on 05 Oct 2012, 06:18 PM
Fixed it. Turns out RadGridView has a property `RowDetailsTemplateSelector`. Using the following XAML:


    <telerik:RadGridView x:Name="resultsgrid"
                                    RowDetailsTemplateSelector="{StaticResource detailsTemplateSelector}"
                                    ItemsSource="{Binding ViewableItems}"
                                    AutoGenerateColumns="False"
                                    Margin="0,0,0,30"
                                    IsReadOnly="True"
                                    >


And completely deleting the `RowDetailsTemplate` previously defined, it now functions properly.
Tags
GridView
Asked by
Tory
Top achievements
Rank 1
Answers by
Tory
Top achievements
Rank 1
Share this question
or