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

No data template

3 Answers 530 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Datafyer
Top achievements
Rank 1
Veteran
Datafyer asked on 15 Aug 2010, 05:54 AM
I would like for the RadGridView to display something like "No data to display" when there are no bound items to the RadGridView. I found some code online which solves the problem, however I would like to define it application wide.

I attempted to subclass RadGridView which compiles fine. However, whenever I use this subclass I get a compiler error, "

Cannot set Name attribute value {0} on element {1}. {1} is under the scope of element {2}, which already had a name registered when it was defined in another scope."


Which I guess is a known limitation of WPF. I would just like to specify the no row template once since I have an application with 30+ instances of RadGridView.

The code I found is from here, and is listed below:

    <interactivity:Interaction.Behaviors>
    <local:EmptyDataTemplateBehavior>
        <local:EmptyDataTemplateBehavior.EmptyDataTemplate>
            <DataTemplate>
                <TextBlock Text="No data to display" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding MessageVisibility}" />
            </DataTemplate>
        </local:EmptyDataTemplateBehavior.EmptyDataTemplate>
    </local:EmptyDataTemplateBehavior>
</interactivity:Interaction.Behaviors>

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 18 Aug 2010, 02:57 PM
Hi Patrick,

Please use the attached project for reference. It has an inherited RadGridView, which encapsulates the logic for the no items message. This way  there is no need to use attached behavior at all.


Greetings,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Datafyer
Top achievements
Rank 1
Veteran
answered on 18 Aug 2010, 08:59 PM
Very nice.
Thank you.
0
Brian Stanek
Top achievements
Rank 2
answered on 28 Aug 2015, 08:51 PM

I know that this is a very old post, but I have seen it referenced a few times and ran into it myself as a suggested solution.  But I have found an easier method using a BooleanToVisibility converter.  And this is a pure XAML solution.

<telerik:RadGridView x:Name="gridView"
         ItemsSource="{Binding Path=PolicyTypeList}"
         IsReadOnly="True" CanUserSortGroups="False"
         ShowGroupPanel="False" EnableLostFocusSelectedState="True"
         IsFilteringAllowed="False"
         ColumnWidth="*"
         RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False">
<telerik:RadGridView.ChildTableDefinitions>
<telerik:GridViewTableDefinition />
</telerik:RadGridView.ChildTableDefinitions>
<telerik:RadGridView.HierarchyChildTemplate>
<DataTemplate>
    <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <TextBlock Grid.Row="0"
           Visibility="{Binding ItemsSource.IsEmpty, Converter={StaticResource BoolToVisible},ElementName=childGrid}"
           >No Policy Applications Found!</TextBlock>
    <telerik:RadGridView Name="childGrid" Grid.Row="1"                                         
           Visibility="{Binding ItemsSource.IsEmpty, Converter={StaticResource BoolToVisible},ConverterParameter=Invert,ElementName=childGrid}"
             ItemsSource="{Binding Path=ChildRecords}"
             IsReadOnly="True" CanUserSortGroups="False"
             ShowGroupPanel="False" EnableLostFocusSelectedState="True"
             IsFilteringAllowed="False"
             Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}"
             ColumnWidth="*"
             RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False">
        <telerik:RadGridView.Columns>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>
    </Grid>
</DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>
<telerik:RadGridView.Columns>
</telerik:RadGridView.Columns>
</telerik:RadGridView>

Tags
GridView
Asked by
Datafyer
Top achievements
Rank 1
Veteran
Answers by
Pavel Pavlov
Telerik team
Datafyer
Top achievements
Rank 1
Veteran
Brian Stanek
Top achievements
Rank 2
Share this question
or