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:
VB:
Thanks,
Paul Leedham
http://gis.hudson.oh.us/GIShome/
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> |
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 Object, ByVal 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.Object, ByVal 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.Object, ByVal 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/