Hiding GridView when empty

8 posts, 0 answers
  1. haagel
    haagel avatar
    52 posts
    Member since:
    Feb 2010

    Posted 13 Apr 2010 Link to this post

    I'm trying to hide my GridView when it is empty with a trigger, but I'm having trouble with that. The problem seems to be that Items.Count doesn't update when the ItemsSource of the GridView is updated.

    I have a GridView and a TextBlock like this:

    <telerikGridView:RadGridView Name="MyGrid" 
        ItemsSource="{Binding MyBindingList, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
        Style="{StaticResource MyGridStyle}"
        ... 
    </telerikGridView:RadGridView> 
     
    <TextBlock Text="No records..." Style="{StaticResource NoRecordsTextStyle}" /> 

    And they reference these styles:

    <Style x:Key="MyGridStyle" TargetType="telerikGridView:RadGridView"
        <Setter Property="Visibility" Value="Visible" /> 
        <Style.Triggers> 
            <DataTrigger Binding="{Binding ElementName=MyGrid, Path=Items.Count}" Value="0"
                <Setter Property="Visibility" Value="Collapsed" /> 
            </DataTrigger> 
        </Style.Triggers> 
    </Style> 
                        
    <Style x:Key="NoRecordsTextStyle" TargetType="TextBlock"
        <Setter Property="Visibility" Value="Collapsed" /> 
        <Style.Triggers> 
            <DataTrigger Binding="{Binding ElementName=MyGrid, Path=Items.Count}" Value="0"
                <Setter Property="Visibility" Value="Visible" /> 
            </DataTrigger> 
        </Style.Triggers> 
    </Style> 

    So the default is that the GridView is visible and the TextBlock is collapsed. When Items.Count is 0, i.e. when there are no records to show, the triggers make sure that the GridView is collapsed and the TextBlock is visible.

    What happens is that the GridView never shows up but the TextBlock does, even though the GridView has records. If I use exactly the same code but swap out the GridView to a standard WPF ListBox it all works fine.

    After some experimenting I've come to the conclusion that it is the Items.Count property that is the problem. It never gets updated. Initially the source of the GridView is empty and thus Items.Count is 0. But when I add items to the source (which I do immediately when the app starts) the Items.Count still remains 0.

    Is this a known issue? How can I get around it? Or am I missing something?

    Thanks // David
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 13 Apr 2010 Link to this post

    Hi David Haglund,

    I believe this blogpost deals with a problem simillar to yours.

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. haagel
    haagel avatar
    52 posts
    Member since:
    Feb 2010

    Posted 13 Apr 2010 Link to this post

    Thanks, but that is not really what I'm looking for. I want to hide the GridView completely when there are no records to display.

    And as I said, I have code that work if I use a standard ListBox or DataGrid. The problem is that the Items.Count property on the GridView doesn't update as it should...
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 15 Apr 2010 Link to this post

    Hi David Haglund,

    We have tested the scenario, indeed there appears to be a problem with Items.Count used in a DataTrigger. Thank you for reporting the problem ! I have updated your Telerik points.

    As a workaround I may suggest to use the Items.IsEmpty property instead (tested and working).

    Something like:

    <DataTrigger Binding="{Binding ElementName=myGrid, Path=Items.IsEmpty}" Value="True">
                       <Setter Property="Visibility" Value="Visible" />
                   </DataTrigger>

    Greetings,
    Maya
    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.
  6. haagel
    haagel avatar
    52 posts
    Member since:
    Feb 2010

    Posted 19 Apr 2010 Link to this post

    I'm afraid it doesn't work for me though... :(
  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 20 Apr 2010 Link to this post

    Hi David Haglund,

    Please let me know the exact version of the telerik dlls you are using and  I wil prepare a working sample app for you .

    Regards,
    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.
  8. Brad
    Brad avatar
    2 posts
    Member since:
    Aug 2011

    Posted 20 Sep 2011 Link to this post

    This doesn't work for me either.  And I am on the latest build.  2011.2.712.40

    <Style TargetType="{x:Type D:Hyperlink}" BasedOn="{StaticResource {x:Type D:Hyperlink}}">
        <Setter Property="IsEnabled" Value="True"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding ElementName=dgTask, Path=Items.IsEmpty}" Value="True">
                <Setter Property="IsEnabled" Value="False"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 23 Sep 2011 Link to this post

    Hello Brad,

    Could you share a bit more details for the exact scenario that you want to get ? Where is the Hyperlink defined - is it outside the grid or in a particular cell template ? Generally, any relevant information or code-snippet considering the grid would be helpful.
     

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready