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

[Solved] CellTemplate missing in GridView

5 Answers 189 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Deven
Top achievements
Rank 1
Deven asked on 18 Jun 2009, 10:05 AM
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

5 Answers, 1 is accepted

Sort by
0
Kalin Milanov
Telerik team
answered on 19 Jun 2009, 03:54 PM
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.
0
Deven
Top achievements
Rank 1
answered on 22 Jun 2009, 08:10 AM
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>

 

0
Accepted
Vlad
Telerik team
answered on 22 Jun 2009, 08:23 AM
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.
0
Deven
Top achievements
Rank 1
answered on 22 Jun 2009, 12:31 PM
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?

0
Hristo Deshev
Telerik team
answered on 23 Jun 2009, 09:12 AM
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.
Tags
General Discussions
Asked by
Deven
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
Deven
Top achievements
Rank 1
Vlad
Telerik team
Hristo Deshev
Telerik team
Share this question
or