CellTemplate missing in GridView

6 posts, 1 answers
  1. Deven
    Deven avatar
    33 posts
    Member since:
    Apr 2009

    Posted 18 Jun 2009 Link to this post

    I am using SL3 and the respective Telerik controls.
    I have the following namespaces in the xaml.

     

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"

    As shown in the sample code, I am not able to see CellTemplate under GridViewColumn or GridViewDataColumn. I see CellStyle, but that is not what I am looking for. What am I missing here?

    I am trying to add a "Select" HyperLink column, on click of which the user will be navigated to Details screen with respective data. This is a common task, so if there is a better way (instead of using a select link column), I would love to know.

    Thanks much.
    Deven

  2. Kalin Milanov
    Admin
    Kalin Milanov avatar
    447 posts

    Posted 19 Jun 2009 Link to this post

    Hi Deven,

    To edit the template of the cell you can simply do the following:
    <Style x:Key="MyCellStyle" TargetType="grid:GridViewCell">  
        <Setter Property="Template> 
            <Setter.Value> 
                <ControlTemplate TargetType="grid:GridViewCell">  
                     <!-- Place your cell template here --> 
                </ControlTemplate> 
            </Setter.Value> 
        </Setter> 
    </Style> 
    Please note that the grid namespace should be defined as follows:
    xmlns:grid="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" 
    The final step will be to apply this style to the cell using a StaticResource

    As for the second part of your question. Please review this example for more information on how to make a hyperlink in the column.

    Kind regards,
    Kalin Milanov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Deven
    Deven avatar
    33 posts
    Member since:
    Apr 2009

    Posted 22 Jun 2009 Link to this post

    Thanks for the reply. I already new about the cell style from one of teleriks example. However, since other example demonstrated use of CellTemplate, I was wondering if there is something missing on my side that I cannot see CellTemplate. Is CellTemplate deprecated?

    I have implemented the CellStyle now, but I have one issue, when I have to click thrice on the hyper link for it to work. First click on the row to select it (clicking on hyper link does not select the row :o. ) and then click on hyperlink (I guess activates the cell edit mode) and then the final click on the link. Is there a way that when user clicks on link, the row is selected and the click event is fired with with correct row datacontext?


    <

     

    telerikGridView:RadGridView AutoGenerateColumns="False" IsFilteringAllowed="True" ShowGroupPanel="True"
    ColumnsWidthMode="Fill" IsReadOnly="True" SelectedItem="{Binding SelectedExclusionSummary, Mode=TwoWay}"
    ItemsSource="{Binding ExclusionSummaryCollection}">

     

     

     

        <telerikGridView:RadGridView.Columns>

     

     

     

     

     

            <telerikGridView:GridViewDataColumn HeaderText="Person Name" DataMemberPath="PersonName" />

     

     

     

            <telerikGridView:GridViewDataColumn HeaderText="Category" DataMemberPath="CategoryDescription" />

     

     

     

            <telerikGridView:GridViewDataColumn HeaderText="Start Date" DataMemberBinding="StartDate" />

     

     

     

            <telerikGridView:GridViewDataColumn HeaderText="End Date" DataMemberBinding="EndDate" />

     

     

     

     

     

     

     

     

            <telerikGridView:GridViewDataColumn>
                <telerikGridView:GridViewDataColumn.CellStyle>
                    <Style TargetType="tgv:GridViewCell">
                        <Setter Property="Template">
                            <Setter.Value>

     

     

     

                                <ControlTemplate TargetType="tgv:GridViewCell">

     

     

     

                                    <Border BorderThickness="{TemplateBinding BorderThickness}" 
                                            
    BorderBrush="{TemplateBinding BorderBrush}"  Background="{TemplateBinding Background}" >

     

     

     

                                        <HyperlinkButton Content="Select" VerticalAlignment="Center" HorizontalAlignment="Center"

     

     

                                                Loaded="LoadContext" Cmd:CommandManager.CommandEventName="Click"

     

     

                                                Cmd:CommandManager.Command="{Binding SelectCommand}"/>

     

     

     

                                    </Border>

     

     

     

                                </ControlTemplate>

     

     

     

                            </Setter.Value>

     

     

     

                        </Setter>

     

     

     

                    </Style>

     

     

     

                </telerikGridView:GridViewDataColumn.CellStyle>

     

     

     

            </telerikGridView:GridViewDataColumn>

     

     

     

        </telerikGridView:RadGridView.Columns>

     

     

     

    </telerikGridView:RadGridView>

     

  4. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 22 Jun 2009 Link to this post

    Hello Deven,

    CellTemplate is new property introduced in Q1 2009 SP1 - you need our latest build.

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Deven
    Deven avatar
    33 posts
    Member since:
    Apr 2009

    Posted 22 Jun 2009 Link to this post

    Thanks. I downloaded the latest build and can see the CellTemplate. Thanks much for that.

    Is there a way to select the row, when the link is clicked upon?

  6. Hristo Deshev
    Admin
    Hristo Deshev avatar
    559 posts

    Posted 23 Jun 2009 Link to this post

    Hello Deven,

    The HyperlinkButton control eats up mouse click events, and maybe that prevents row selection. I managed to work around that by handling the HyperlinkButton Click event and selecting the row:

    private void Hyperlink_Click(object sender, RoutedEventArgs e) 
        var row = ((FrameworkElement) sender).ParentOfType<GridViewRow>(); 
        row.IsSelected = true

    Note that the ParentOfType method is an extension method, and you will need a using clause for the Telerik.Windows.Controls namespace in your file.

    Kind regards,
    Hristo Deshev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top