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

DeepClear

4 Answers 68 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 28 May 2011, 02:05 AM
Hi

The following code clears all rows in the grid.  I also need to clear out the GridViewHeader(s).  Can this be done?

Thanks
Rich

public static void DeepClear(RadGridView grid)
        
            grid.Columns.Clear();
            IEnumerable<GridViewRow> rows = grid.ChildrenOfType<GridViewRow>().Where(s => s.Item != null);
            foreach (GridViewRow row in rows)
            {
                  
                if (row.ChildrenOfType<RadGridView>().Count > 0)
                {
                    DeepClear(row.ChildrenOfType<RadGridView>().First());
                }
            }
        }



4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 31 May 2011, 08:37 AM
Hello Richard Harrigan,

 I have tested the DeepClear method and it clears all the data that is shown on the grid, including the values in the Header cells. I am not sure if you mean to clear the values in the GridViewHeader, or to remove the entire GridViewHeader.

Generally it is not a good idea to work with the Visual Elements instead of Data Elements. It is better that you use the following approach to clear all the GridView's data and its Headers:

private void DeepClear(RadGridView grid)
{
            grid.ItemsSource = null;
            grid.Columns.Clear();
}

I have prepared a sample project. Would you please review it and clarify what exactly do you mean by "clear out the GridViewHeader(s)"?

All the best,
Didie
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
Richard Harrigan
Top achievements
Rank 1
answered on 02 Jun 2011, 06:44 PM
Hi.

That did not work for me.

Your example does not include the condition that causes my problem.

- I am generating the data dynamically using the light-weight data table

- After executing the deep clear I regenerate the data based on new column selections for the same tables

- Any header that was shown by being expanded in the previous state of the grid is now shown in the new version.  That is, in the new version when I expand I get two headers.  I also get two RadGridView_DataLoading events. If I deepclear and reload again I wind up with three headers. 

My app is generating queries by example so this is a iterave process and I need to totally cear out everything so that the grid is in the same state as generated in the xaml.

I don't know if this effects anything but you may want to look at the xaml.  It contains a GridHeader style to put a button on the header.

Thanks
Rich

<telerik:RadGridView Name="radGridView"
                            Visibility="Collapsed"
                            HeaderRowStyle="{StaticResource style1}"
                            ItemsSource="{Binding Collection}"
                            ShowGroupPanel="False"   
                            RowIsExpandedChanging="radGridView_RowIsExpandedChanging"
                            DataLoading="radGridView_DataLoading"
                            RowLoaded="radGridView_RowLoaded"
                            SelectionMode="Single"
                            SelectionChanged="radGridView_SelectionChanged"                          
                            AutoGenerateColumns="False">
       </telerik:RadGridView>

<UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  x:Class="Cloudburst.PaneForm.QueryDesignForm"
    xmlns:telerikGridViewFilter="clr-namespace:Telerik.Windows.Controls.GridView.Filter"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
  
    <UserControl.Resources>
        <SolidColorBrush x:Key="GridView_HeaderRowInnerBorder"
                         Color="#FF4B4B4B" />
        <telerik:Office_BlackTheme x:Key="Theme" />
        <SolidColorBrush x:Key="GridView_HeaderInnerBorder"
                         Color="#FF4B4B4B" />
        <LinearGradientBrush x:Key="GridView_HeaderBackground"
                             EndPoint="0.5,1"
                             StartPoint="0.5,0">
            <GradientStop Color="#FF5B5B5B"
                          Offset="1" />
            <GradientStop Color="#FF868686" />
            <GradientStop Color="#FF4F4F4F"
                          Offset="0.42" />
            <GradientStop Color="#FF0E0E0E"
                          Offset="0.43" />
        </LinearGradientBrush>
        <DataTemplate x:Key="GridViewHeaderIndentCellDataTemplate">
            <telerik:GridViewHeaderIndentCell telerik:StyleManager.Theme="{StaticResource Theme}" />
        </DataTemplate>
        <telerik:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <ControlTemplate x:Key="GridViewHeaderRowTemplate"
                         TargetType="telerik:GridViewHeaderRow">
            <telerik:SelectiveScrollingGrid>
                <telerik:SelectiveScrollingGrid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </telerik:SelectiveScrollingGrid.ColumnDefinitions>
                <Border x:Name="PART_GridViewHeaderRowBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Grid.ColumnSpan="4"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        Padding="{TemplateBinding Padding}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                    <Border BorderBrush="{StaticResource GridView_HeaderRowInnerBorder}"
                            BorderThickness="1"
                            Background="{TemplateBinding Background}" />
                </Border>
                <telerik:DataCellsPresenter x:Name="PART_DataCellsPresenter"
                                            Grid.Column="3"
                                            telerik:StyleManager.Theme="{StaticResource Theme}" />
                <Border x:Name="PART_IndicatorPresenter"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0,0,1,1"
                        telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
                        Visibility="{TemplateBinding RowIndicatorVisibility}"
                        Width="25">
                    <Border BorderBrush="{StaticResource GridView_HeaderInnerBorder}"
                            BorderThickness="1"
                            Background="{StaticResource GridView_HeaderBackground}">
                        <telerik:RadButton Click="PropertyButton_Click"
                                            IsBackgroundVisible="False"
                                           ToolTipService.ToolTip="Edit properties"
                                           Margin="0">
                            <Image Source="Images2/Properties_16.png"
                                       
                                   Height="16"
                                   Width="16"></Image>
                        </telerik:RadButton>
                    </Border>
                </Border>
                <telerik:IndentPresenter x:Name="PART_IndentPresenter"
                                         Grid.Column="1"
                                         ItemTemplate="{StaticResource GridViewHeaderIndentCellDataTemplate}"
                                         IndentLevel="{TemplateBinding IndentLevel}"
                                         MinHeight="{TemplateBinding MinHeight}"
                                         telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
                                         telerik:StyleManager.Theme="{StaticResource Theme}" />
                <Border x:Name="PART_HierarchyIndentPresenter"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0,0,1,1"
                        Grid.Column="2"
                        telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
                        Visibility="{Binding HasHierarchy, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}"
                        Width="25">
                    <Border BorderBrush="{StaticResource GridView_HeaderInnerBorder}"
                            BorderThickness="1"
                            Background="{StaticResource GridView_HeaderBackground}" />
                </Border>
            </telerik:SelectiveScrollingGrid>
        </ControlTemplate>
        <LinearGradientBrush x:Key="GridView_HeaderRowBackground"
                             EndPoint="0.5,1"
                             StartPoint="0.5,0">
            <GradientStop Color="#FF5B5B5B"
                          Offset="1" />
            <GradientStop Color="#FF868686" />
            <GradientStop Color="#FF4F4F4F"
                          Offset="0.42" />
            <GradientStop Color="#FF0E0E0E"
                          Offset="0.43" />
        </LinearGradientBrush>
        <SolidColorBrush x:Key="GridView_HeaderRowOuterBorder"
                         Color="#FF848484" />
        <Style x:Key="style1"
               TargetType="telerik:GridViewHeaderRow">
            <Setter Property="Template"
                    Value="{StaticResource GridViewHeaderRowTemplate}" />
            <Setter Property="Background"
                    Value="{StaticResource GridView_HeaderRowBackground}" />
            <Setter Property="MinHeight"
                    Value="27" />
            <Setter Property="BorderBrush"
                    Value="{StaticResource GridView_HeaderRowOuterBorder}" />
            <Setter Property="BorderThickness"
                    Value="1,0,0,1" />
            <Setter Property="VerticalContentAlignment"
                    Value="Stretch" />
            <Setter Property="HorizontalContentAlignment"
                    Value="Stretch" />
            <Setter Property="Padding"
                    Value="0" />
        </Style>
  
    </UserControl.Resources>
      
    <Grid x:Name="LayoutRoot" Background="White">
  
        <telerik:RadGridView Name="radGridView"
                             Visibility="Collapsed"
                             HeaderRowStyle="{StaticResource style1}"
                             ItemsSource="{Binding Collection}"
                             ShowGroupPanel="False"   
                             RowIsExpandedChanging="radGridView_RowIsExpandedChanging"
                             DataLoading="radGridView_DataLoading"
                             RowLoaded="radGridView_RowLoaded"
                             SelectionMode="Single"
                             SelectionChanged="radGridView_SelectionChanged"                          
                             AutoGenerateColumns="False">
        </telerik:RadGridView>
          
    </Grid>
</UserControl>


 
0
Milan
Telerik team
answered on 07 Jun 2011, 12:51 PM

Hello Richard Harrigan,

I am afraid that the supplied code is not enough to reproduce your scenario. Is it possible to send us the whole application? 

Also, I am a bit baffled as to why you need to perform such clear? As far as I can understand you would like to preserve the state of the grid before you change the source (correct me if I am wrong). 



All the best,
Milan
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
Richard Harrigan
Top achievements
Rank 1
answered on 07 Jun 2011, 06:30 PM
Hi

I don't need to save any information, i have the context saved elsewhere.  What I was looking for was a simple way to reset the grid back to it's original state when initially instantiated.   I made a change to create the grid in code and instantiatea new version as needed.  That seems to be working out ok.

Thanks
Rich
Tags
GridView
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Richard Harrigan
Top achievements
Rank 1
Milan
Telerik team
Share this question
or