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

Sorting A DataTemplate Column

2 Answers 56 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stacey Haslag
Top achievements
Rank 1
Stacey Haslag asked on 17 May 2011, 02:41 PM
I have a GridView that is bound to a "SearchResult" object. Within this "SearchResult" object, is another "ChaserAssociation" object. I have a column in my GridView that I am using the CellTemplate approach with, because I want to access specific properties within the "ChaserAssociation" object in this column.

I would also love to utilize the built-in sorting for this column. I have tried multiple combinations of specifying a SortMemberPath property, but no matter what combination I try, I always recieve this error message:

XamlParseException occured: Element is already the child of another element. [Line: 0 Position: 0]

Here is my GridView, the column that is causing me issues is the "Associated To" column:
<telerik:RadGridView x:Name="RadResultsGridTest" Margin="0, 5, 0, 0" IsReadOnly="True" FontWeight="Bold" AutoGenerateColumns="False" 
                     ShowGroupPanel="False" telerik:StyleManager.Theme="Windows7" SelectionMode="Extended" 
                     ItemsSource="{Binding SearchResults}">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Due Date" DataMemberBinding="{Binding DueDate, StringFormat=d}"/>
        <telerik:GridViewDataColumn Header="Category" DataMemberBinding="{Binding Category.Description}"/>
        <telerik:GridViewDataColumn Header="Title" DataMemberBinding="{Binding Title}"/>
        <telerik:GridViewDataColumn Header="Associated To" Width="*" SortMemberPath="{Binding AssociatedToDisplayDescription}">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <HyperlinkButton Content="{Binding AssociatedToDisplayDescription}" CommandParameter="{Binding ChaserAssociation}"
                                     Command="{Binding Source={StaticResource DataContextProxy}, Path=DataSource.AssociateCommand}" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>


Thanks for your help!
Stacey

2 Answers, 1 is accepted

Sort by
0
Stacey Haslag
Top achievements
Rank 1
answered on 17 May 2011, 06:37 PM
I tried adding a sorting event to my GridView, so I could attempt to handle the sorting manually. This sorting event fires for all my other columns, but I cannot get it to fire on my "Associated To" custom column:

<telerik:RadGridView x:Name="RadResultsGrid" Margin="0, 5, 0, 0" IsReadOnly="True" FontWeight="Bold" AutoGenerateColumns="False" 
                                 SelectionMode="Extended" ItemsSource="{Binding PagedSource, ElementName=radDataPager}" 
                                 ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" telerik:StyleManager.Theme="Windows7"
                                 SelectionChanged="RadResultsGrid_SelectionChanged" Sorting="RadResultsGrid_Sorting">
...(other stuff).......
<telerik:GridViewDataColumn Header="Associated To" Width="*" IsSortable="True">
0
Stacey Haslag
Top achievements
Rank 1
answered on 17 May 2011, 06:45 PM
Okay, I figured out what I was doing wrong - I was not specifying a DataMemberBinding. Once I specified this, Sorting started working.
Consider this post closed.

<telerik:GridViewDataColumn Header="Associated To" Width="*" IsSortable="True" DataMemberBinding="{Binding AssociatedToDisplayDescription}">
Tags
GridView
Asked by
Stacey Haslag
Top achievements
Rank 1
Answers by
Stacey Haslag
Top achievements
Rank 1
Share this question
or