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

Will using a data template in this GridView cause me any problems?

3 Answers 108 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rod
Top achievements
Rank 1
Rod asked on 31 Jan 2014, 09:35 PM
Right now I've got a RadGridView that is using a sort and group headers. I've been thinking of adding an additional field (currently commented out) to give the users more information so they can make more intelligent decisions as to which row in the grid view to select. However, as has been pointed out to me, if I did that, then there would be the date of birth, appointment date and interview date, one right after another. Making a rather busy UI which would be hard to figure out. So I've been thinking about replacing the GridViewDataColumns I currently have displayed for each detail row, with a data template instead. That way I could put in labels, probably put that information into a regular XAML grid or maybe a stack panel, and just make the UI easier to read and interpret. But I'm concerned about potentially messing up my sort and group headers of the RadGridView. This is the first time I've used those in a WPF app. So, my question is can I replace those individual GridViewDataColumns I currently use for the details rows, with a DataTemplate and still not mess up my sorts and group headers?

Here is the XAML. The ItemsSource is assigned in the code-behind:

<telerik:RadGridView  VerticalAlignment="Stretch" AutoGenerateColumns="False" DataMember="ClientNumber"
    x:Name="grdClients" telerikControls:StyleManager.Theme="Transparent" d:DataContext="{d:DesignData Source=/SampleData/ASISelectClientSampleCollection.xaml}"
    IsReadOnly="True" ShowColumnHeaders="False" ShowGroupPanel="False"
    RowIndicatorVisibility="Collapsed"
    IsFilteringAllowed="False" AutoExpandGroups="True" FontSize="16" SelectionChanged="grdClients_SelectionChanged"
    ItemsSource="{Binding}" HorizontalAlignment="Left" MouseDoubleClick="grdClients_MouseDoubleClick" Margin="50,25,0,0" >
 
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn UniqueName="ClientNumber" Width="SizeToCells">
            <telerik:GridViewDataColumn.ToolTipTemplate>
                <DataTemplate>
                    <TextBlock Text="Client Number" />
                </DataTemplate>
            </telerik:GridViewDataColumn.ToolTipTemplate>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn UniqueName="LastName">
            <telerik:GridViewDataColumn.ToolTipTemplate>
                <DataTemplate>
                    <TextBlock Text="Last Name" />
                </DataTemplate>
            </telerik:GridViewDataColumn.ToolTipTemplate>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn UniqueName="FirstNames">
            <telerik:GridViewDataColumn.ToolTipTemplate>
                <DataTemplate>
                    <TextBlock Text="First Name" />
                </DataTemplate>
            </telerik:GridViewDataColumn.ToolTipTemplate>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn UniqueName="CaseNumber" Width="SizeToCells">
            <telerik:GridViewDataColumn.ToolTipTemplate>
                <DataTemplate>
                    <TextBlock Text="Case Number" />
                </DataTemplate>
            </telerik:GridViewDataColumn.ToolTipTemplate>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn UniqueName="DateOfBirth" DataFormatString="{}{0:d}" Width="SizeToCells">
            <telerik:GridViewDataColumn.ToolTipTemplate>
                <DataTemplate>
                    <TextBlock Text="DOB" />
                </DataTemplate>
            </telerik:GridViewDataColumn.ToolTipTemplate>
        </telerik:GridViewDataColumn>
        <!--<telerik:GridViewDataColumn UniqueName="AppointmentDate" DataFormatString="{}{0:d}" Width="SizeToCells">
            <telerik:GridViewDataColumn.ToolTipTemplate>
                <DataTemplate>
                    <TextBlock Text="Appointment date - the scheduled date of the assessment" />
                </DataTemplate>
            </telerik:GridViewDataColumn.ToolTipTemplate>
        </telerik:GridViewDataColumn>-->
        <telerik:GridViewDataColumn UniqueName="InterviewDate" DataFormatString="{}{0:d}" Width="SizeToCells">
            <telerik:GridViewDataColumn.ToolTipTemplate>
                <DataTemplate>
                    <TextBlock Text="Interview Date - the date the assessment began" />
                </DataTemplate>
            </telerik:GridViewDataColumn.ToolTipTemplate>
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
    <telerik:RadGridView.SortDescriptors>
        <telerik:SortDescriptor Member="LastName" SortDirection="Ascending" />
        <telerik:SortDescriptor Member="FirstNames" SortDirection="Ascending" />
        <telerik:SortDescriptor Member="CaseNumber" SortDirection="Descending" />
    </telerik:RadGridView.SortDescriptors>
    <telerik:RadGridView.GroupDescriptors>
        <telerik:GroupDescriptor Member="ClientNumber"/>
    </telerik:RadGridView.GroupDescriptors>
    <telerik:RadGridView.GroupHeaderTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <StackPanel  Orientation="Horizontal" Width="250">
                    <TextBlock Text="{Binding Group.Items[0].LastName}" />
                    <TextBlock Text=", " />
                    <TextBlock Text="{Binding Group.Items[0].FirstNames}" />
                </StackPanel>
                <StackPanel Margin="10,0,0,0" Orientation="Horizontal">
                    <TextBlock Text="{Binding Group.Items[0].SocialSecurityNo}" FontWeight="Bold"  />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </telerik:RadGridView.GroupHeaderTemplate>
</telerik:RadGridView>

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 05 Feb 2014, 04:50 PM
Hello,

I am not sure what do you mean by replacing the GridViewDataColumns you currently have for each detail row, with a data template instead. Do you mean to not have any columns at all? May I ask you to share what is the exact implementation do you consider?

As general tips and tricks on how to keep the performance good with your implementation, you can also refer this documentation article.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Rod
Top achievements
Rank 1
answered on 06 Feb 2014, 04:49 PM
Actually, that is a good question, Didie. I guess what I'm saying is that I'm considering the possibility of replacing several of the GridViewDataColumns with just 1 GridViewDataColumn, which would have a data template associated with it. However, in thinking that through that too may have a problem, because data binding is to the GridViewDataColumn, isn't it? And I want to be able to format the data in such a way that it's displayed not in a row but in a grid or stack panel. The issue is that right now I would show 3 dates, one right after another, and that only confuses the users. Therefore, I thought that if I could put them into a grid or stack panel, with labels (TextBlocks) describing each data field, that would make it easier for the user to comprehend what they're seeing.
0
Accepted
Dimitrina
Telerik team
answered on 11 Feb 2014, 09:56 AM
Hi,

You could do that redefining the CellTemplate of the column. This article explains how to do so. You can set only one property as a DataMemberBinding of such a column. You can also set SortMemberPath, GroupMemberPath or FilterMemberPath for the column, but it will be per one property only.
You could also use a GridViewColumn without specifying any binding.

Regards,
Didie
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

Tags
GridView
Asked by
Rod
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Rod
Top achievements
Rank 1
Share this question
or