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

GridView Print No Contents

3 Answers 131 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Betsy
Top achievements
Rank 1
Betsy asked on 21 Jul 2011, 08:13 PM
I copied the code directly from the demo into my project for printing a grid.  It prints, and shows the headers and correct number of rows but does not show any cell text.  What could be wrong???  I was using the Windows7Theme but commented that out and had the same issue.  This is WPF 4.0, WPF Controls 2010.3.1314.40.  I know this is a few versions behind but the last time I checked the 2011 release it had a bug with the TabControl and Prism interaction that I do not have time to work around.

EDIT: I have upgraded my project to the latest WPF Controlss (2011 Q2) and now it works for all columns EXCEPT hyperlinks (or maybe its just related to columns with cell templates).  How can I get hyperlink/celltemplate columns to display?

<telerik:RadGridView.Columns>
  <telerik:GridViewDataColumn Header="Account Number" DataMemberBinding="{Binding AccountNumber}" ShowDistinctFilters="False" >
    <telerik:GridViewDataColumn.CellTemplate>
      <DataTemplate>
        <TextBlock><Hyperlink Command="{Binding DataContext.SelectCommand, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}" CommandParameter="{Binding}"><InlineUIContainer
                  <TextBlock Text="{Binding AccountNumber}"/>
              </InlineUIContainer></Hyperlink></TextBlock>
      </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
    <telerik:GridViewDataColumn.AggregateFunctions>
      <telerik:CountFunction Caption="Count:" />
    </telerik:GridViewDataColumn.AggregateFunctions>
  </telerik:GridViewDataColumn>
  <telerik:GridViewDataColumn Header="Account Name" DataMemberBinding="{Binding AccountName}" Width="*" ShowDistinctFilters="False"  FooterCellStyle="{StaticResource GridNoLinesFooterStyle}"/>
  <telerik:GridViewDataColumn Header="Association" DataMemberBinding="{Binding AssociationName}"  FooterCellStyle="{StaticResource GridNoLinesFooterStyle}"/>
  <telerik:GridViewDataColumn Header="Status" DataMemberBinding="{Binding AccountStatusName}"  FooterCellStyle="{StaticResource GridNoLinesFooterStyle}" />
</telerik:RadGridView.Columns>


3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 27 Jul 2011, 02:08 PM
Hello Heather,

Please paste me your printing related code behind and I will gather a small example for you. As alternative if you have a runnable project , I can modify it for you and send the modified version back .

Without having this , I am not sure I can gather the proper sample , as there are several possible approaches to printing and I am not exactly sure which one you are using.



Greetings,
Pavel Pavlov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Betsy
Top achievements
Rank 1
answered on 27 Jul 2011, 02:17 PM
I am using the PrintExtensions class and I call the Print method passing in a WPF RadGridView.

Public NotInheritable Class PrintExtensions
  Private Sub New()
  End Sub
  Private Shared Function ToFixedDocument(ByVal element As FrameworkElement, ByVal dialog As Windows.Controls.PrintDialog) As FixedDocument
    Dim capabilities As PrintCapabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket)
    Dim pageSize As New Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight)
    Dim extentSize As New Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight)
  
    Dim fixedDocument As New FixedDocument()
  
    element.Measure(New Size(Double.PositiveInfinity, Double.PositiveInfinity))
    element.Arrange(New Rect(New Point(0, 0), element.DesiredSize))
  
    Dim totalHeight As Double = element.DesiredSize.Height
  
    Dim yOffset As Double = 0
    While yOffset < totalHeight
      Dim brush As New VisualBrush(element)
      brush.Stretch = Stretch.None
      brush.AlignmentX = AlignmentX.Left
      brush.AlignmentY = AlignmentY.Top
      brush.ViewboxUnits = BrushMappingMode.Absolute
      brush.TileMode = TileMode.None
      brush.Viewbox = New Rect(0, yOffset, extentSize.Width, extentSize.Height)
  
  
      Dim pageContent As New PageContent()
      Dim page As New FixedPage()
      DirectCast(pageContent, IAddChild).AddChild(page)
  
      fixedDocument.Pages.Add(pageContent)
      page.Width = pageSize.Width
      page.Height = pageSize.Height
  
      Dim canvas As New Windows.Controls.Canvas()
      FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth)
      FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight)
      canvas.Width = extentSize.Width
      canvas.Height = extentSize.Height
      canvas.Background = brush
  
      page.Children.Add(canvas)
  
      yOffset += extentSize.Height
    End While
    Return fixedDocument
  End Function
  
  Private Shared Function ToPrintFriendlyGrid(ByVal source As GridViewDataControl) As GridViewDataControl
    Dim grid As New RadGridView()
  
    grid.ItemsSource = source.ItemsSource
    grid.RowIndicatorVisibility = Visibility.Collapsed
    grid.ShowGroupPanel = False
    grid.CanUserFreezeColumns = False
    grid.IsFilteringAllowed = False
    grid.AutoExpandGroups = True
    grid.AutoGenerateColumns = False
    grid.HorizontalAlignment = HorizontalAlignment.Stretch
  
    grid.RowStyle = source.RowStyle
    grid.RowStyleSelector = source.RowStyleSelector
    grid.AlternationCount = source.AlternationCount
    grid.AlternateRowBackground = source.AlternateRowBackground
    grid.AlternateRowStyle = source.AlternateRowStyle
    grid.AlternateRowStyleSelector = source.AlternateRowStyleSelector
    grid.ColumnBackground = source.ColumnBackground
  
    grid.SelectedItems.Clear()
  
    For Each column As GridViewColumn In source.Columns.OfType(Of GridViewColumn)()
      Dim columnType As Type = column.GetType()
      Dim newColumn As GridViewColumn = DirectCast(Activator.CreateInstance(columnType), GridViewColumn)
      newColumn.CopyPropertiesFrom(column)
      grid.Columns.Add(newColumn)
    Next
  
    StyleManager.SetTheme(grid, StyleManager.GetTheme(grid))
  
    grid.SortDescriptors.AddRange(source.SortDescriptors)
    grid.GroupDescriptors.AddRange(source.GroupDescriptors)
    grid.FilterDescriptors.AddRange(source.FilterDescriptors)
  
    Return grid
  End Function
  
  Public Shared Sub PrintPreview(ByVal source As GridViewDataControl)
    Dim window As New Window()
    window.Title = "Print Preview"
  
    Dim documentViewer As New Windows.Controls.DocumentViewer()
    documentViewer.Document = ToFixedDocument(ToPrintFriendlyGrid(source), New Windows.Controls.PrintDialog())
    window.Content = documentViewer
  
    window.ShowDialog()
  End Sub
  
  Public Shared Sub Print(ByVal source As GridViewDataControl, ByVal showDialog As Boolean)
    Dim dialog As New Windows.Controls.PrintDialog()
    Dim dialogResult As System.Nullable(Of Boolean) = If(showDialog, dialog.ShowDialog(), True)
  
    If dialogResult = True Then
      Dim viewer As New Windows.Controls.DocumentViewer()
      viewer.Document = ToFixedDocument(ToPrintFriendlyGrid(source), dialog)
      dialog.PrintDocument(viewer.Document.DocumentPaginator, Nothing)
    End If
  End Sub
End Class
0
Pavel Pavlov
Telerik team
answered on 28 Jul 2011, 05:01 PM
Hi Heather,

I am not sure about the reason , but here are my observations :

As you may have noticed , a clone RadGridView is created for printing purposes in the ToPrintFriendlyGrid.
Private Shared Function ToPrintFriendlyGrid(ByVal source As GridViewDataControl) As GridViewDataControl
 
    Dim grid As New RadGridView()
 
   
  
    grid.ItemsSource = source.ItemsSource

Your "hyperlink" column has some specifics -
it relies on the visual tree and the DataContext ( which both are not present in the "cloned" grid). I believe this prevents it from being rendered in the printing clone of RadGridView.

<telerik:GridViewDataColumn Header="Account Number" DataMemberBinding="{Binding AccountNumber}" ShowDistinctFilters="False" > <telerik:GridViewDataColumn.CellTemplate> <DataTemplate> <TextBlock><Hyperlink Command="{Binding DataContext.SelectCommand, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}" CommandParameter="{Binding}"><InlineUIContainer>   <TextBlock Text="{Binding }"/>  </InlineUIContainer></Hyperlink></TextBlock> </DataTemplate> </telerik:GridViewDataColumn.CellTemplate>

As a workaround I may suggest to extend a bit the method mentioned (ToPrintFriendlyGrid) , and only for the printing clone of RadGridView - replace the hyperlink column wiht a regular data bound column.

Regards,
Pavel Pavlov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
Betsy
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Betsy
Top achievements
Rank 1
Share this question
or