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

Cannot get headers to display when exporting from grid

2 Answers 28 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 06 Apr 2010, 02:17 PM
When exporting from a grid I am not able to export the HeaderRow or HeaderCell elements.  The Row and GroupHeaderRow elements are working fine.
XAML:
<Grid x:Name="LayoutRoot">  
 
        <StackPanel Orientation="Vertical">  
              
            <Button Click="Export_Click" Content="Export" Height="30" ></Button>  
 
            <grid:RadGridView x:Name="DataGrid1"   
                              AutoGenerateColumns="False" 
                              MaxWidth="720" 
                              MaxHeight="500" 
                              Exporting="DataGrid1_Exporting"   
                              ShowColumnHeaders="True" 
                              > 
            <grid:RadGridView.Columns> 
                <grid:GridViewDataColumn Header="Name" DataMemberBinding="{Binding HeadingText}" /> 
                <grid:GridViewDataColumn Header="Path" DataMemberBinding="{Binding ImagePath}" /> 
            </grid:RadGridView.Columns> 
 
        </grid:RadGridView> 
         
            </StackPanel> 
    </Grid> 
VB:
Imports System.Windows.Browser  
Imports System.Windows.Threading  
Imports System.Collections.ObjectModel  
Imports Telerik.Windows.Controls  
Imports System.IO  
 
Partial Public Class MainPage  
    Inherits UserControl  
 
    Public Sub New()  
        InitializeComponent()  
    End Sub 
 
    'Page loaded event.  
    Private Sub MainPage_Loaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded  
        LoadGrid()  
    End Sub 
 
    Private Sub LoadGrid()  
        Dim ToolsCollection As ObservableCollection(Of Tools_Class) = New ObservableCollection(Of Tools_Class)  
        Dim Tools As Tools_Class  
 
        'Set values  
        Tools = New Tools_Class  
        Tools.HeadingText = "Tools" 
        Tools.ImagePath = "../Images/i_tools.png" 
        ToolsCollection.Add(Tools)  
 
        Tools = New Tools_Class  
        Tools.HeadingText = "Bookmarks" 
        Tools.ImagePath = "../Images/many-Glossary.png" 
        ToolsCollection.Add(Tools)  
 
        Tools = New Tools_Class  
        Tools.HeadingText = "Find Address" 
        Tools.ImagePath = "../Images/house-32x32.png" 
        ToolsCollection.Add(Tools)  
 
        Tools = New Tools_Class  
        Tools.HeadingText = "Options" 
        Tools.ImagePath = "../Images/Options1.png" 
        ToolsCollection.Add(Tools)  
 
        DataGrid1.ItemsSource = ToolsCollection  
 
    End Sub 
 
    Private Sub Export_Click(ByVal sender As System.ObjectByVal e As System.Windows.RoutedEventArgs)  
        Dim extension As String = "xls" 
        Dim format As ExportFormat = ExportFormat.Html  
 
        Dim dialog As New SaveFileDialog()  
 
        If dialog.ShowDialog() = True Then 
            Using stream As Stream = dialog.OpenFile()  
                DataGrid1.Export(stream, New GridViewExportOptions())  
            End Using  
        End If 
 
 
    End Sub 
 
    Private Sub DataGrid1_Exporting(ByVal sender As System.ObjectByVal e As Telerik.Windows.Controls.GridViewExportEventArgs)  
        'Format the Header Row  
        If e.Element = ExportElement.HeaderRow OrElse e.Element = ExportElement.HeaderCell Then 
            'MessageBox.Show("this is a header field")  
            e.Height = 40  
            e.Background = Colors.Orange  
            e.Foreground = Colors.White  
            e.FontSize = 20  
            e.FontWeight = FontWeights.Bold  
 
            'Format general rows  
        ElseIf e.Element = ExportElement.Row Then 
            'MessageBox.Show("this is a general field")  
            e.Background = Colors.LightGray  
 
            'Format group header row  
        ElseIf e.Element = ExportElement.GroupHeaderRow Then 
            'MessageBox.Show("this is a group header row field")  
            e.FontFamily = New FontFamily("Verdana")  
            e.Background = Colors.LightGray  
            e.Height = 30  
        End If 
 
    End Sub 
 
End Class 
 
'Simple Class  
Public Class Tools_Class  
    Dim headTxt As String 
    Dim ImagePathTxt As String 
    Public Sub New()  
    End Sub 
 
    Public Property HeadingText() As String 
        Get 
            Return headTxt  
        End Get 
        Set(ByVal value As String)  
            headTxt = value  
        End Set 
    End Property 
 
    Public Property ImagePath() As String 
        Get 
            Return ImagePathTxt  
        End Get 
        Set(ByVal value As String)  
            ImagePathTxt = value  
        End Set 
    End Property 
End Class 
 
 
 

Thanks,

Paul Leedham
http://gis.hudson.oh.us/GIShome/

2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 08 Apr 2010, 06:14 AM
Hi Paul,

Here is an example how to achieve your goal:

If dialog.ShowDialog() = True Then
            Using stream As Stream = dialog.OpenFile()
                Dim options As GridViewExportOptions = New GridViewExportOptions
                options.ShowColumnHeaders = True

                DataGrid1.Export(stream, options)
            End Using
        End If

Best wishes,
Vlad
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
Paul
Top achievements
Rank 1
answered on 08 Apr 2010, 01:10 PM
Thank you...
That resolved my issues.
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Paul
Top achievements
Rank 1
Share this question
or