Option Explicit
Private ma_HeightsPreviewPx() As Long Private ma_HeightsPx() As Long
Private Sub Command1_Click() Dim i As Long Dim l As Long, r As Long, t As Long, b As Long Dim l_Height As Long Dim l_NonReportArea As Long Dim lo_Selected As Collection Dim lo_Focused As ReportRow With Me.ReportControl1 ' Set up storage for each row and preview height ReDim ma_HeightsPreviewPx(.Rows.Count - 1) ReDim ma_HeightsPx(.Rows.Count - 1) ' Force report control to fire Measurement events .SetCustomDraw xtpCustomMeasureRow + xtpCustomMeasurePreviewItem .Redraw ' Seems to be required to force final tally to be correct ' Store the current row selection ' We will be stepping through each row to calculate row heights ' since only visible rows will return their height in pixels/raise measurement events Set lo_Selected = New Collection For i = 0 To .SelectedRows.Count - 1 lo_Selected.Add .SelectedRows.Row(i) Next i Set lo_Focused = .FocusedRow ' Step through each row to force measurement of each row ' Perhaps this could be made more efficient by using MovePageDown ' But this is guaranteed to measure every row .Navigator.MoveFirstRow For i = 0 To .Rows.Count - 1 l_Height = l_Height + ma_HeightsPx(i) + ma_HeightsPreviewPx(i) .Navigator.MoveDown Next i ' Remove the measurement events .SetCustomDraw 0 ' Release memory Erase ma_HeightsPreviewPx Erase ma_HeightsPx ' Restore the original row selections For i = 1 To lo_Selected.Count .SelectedRows.Add lo_Selected.Item(i) Next i Set .FocusedRow = lo_Focused ' Get height of visible report rows area (not including, headers, footers, etc..) .GetElementRect xtpReportElementRectReportArea, l, t, r, b ' Compute non-report height (header, footers, etc...) l_NonReportArea = (.Height / Screen.TwipsPerPixelY) - (b - t) ' Compute total required height .Height = Me.ScaleY(l_Height + l_NonReportArea, vbPixels, ScaleableScaleMode) ' Restore focus to the ReportControl .SetFocus End With End Sub
Private Function ScaleableScaleMode() As ScaleModeConstants ' Make sure we don't raise an error when converting scalemodes for vbUser ScaleableScaleMode = IIf(Me.ScaleMode = vbUser, vbPixels, Me.ScaleMode) End Function
Private Sub Form_Load() Dim i As Long With Me.ReportControl1
.AutoColumnSizing = False .Columns.Add .Columns.Count, "Test", 150, True
' Generate Sample records For i = 1 To 13 With .Records.Add .AddItem i If i Mod 2 = 0 Then .PreviewText = "Preview" If i Mod 4 = 0 Then .PreviewText = .PreviewText & vbNewLine & "Preview" End If If i Mod 8 = 0 Then .PreviewText = .PreviewText & vbNewLine & "Preview" End If End If End With Next i .PreviewMode = True .Populate End With End Sub
Private Sub ReportControl1_MeasurePreviewItem(ByVal Row As XtremeReportControl.IReportRow, ByVal hDC As stdole.OLE_HANDLE, ByVal Width As Long, Height As Long) ' Store height of each preview row ma_HeightsPreviewPx(Row.Index) = Height End Sub
Private Sub ReportControl1_MeasureRow(ByVal Row As XtremeReportControl.IReportRow, ByVal hDC As stdole.OLE_HANDLE, ByVal Width As Long, Height As Long) ' Store height of each row (not including preview height) ma_HeightsPx(Row.Index) = Height End Sub
|