Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Report Control
  New Posts New Posts RSS Feed - Question: Resize control to show all rows.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Question: Resize control to show all rows.

 Post Reply Post Reply
Author
Message
keepITcool View Drop Down
Groupie
Groupie
Avatar

Joined: 08 April 2009
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote keepITcool Quote  Post ReplyReply Direct Link To This Post Topic: Question: Resize control to show all rows.
    Posted: 21 March 2010 at 4:03pm
Hi, need help!
 
I have a control populated with a varying number of rows, some of which may have preview items...
I want to resize the control (within limits) to fit the rows...
 
How do i do this with some degree of simplicity...  In other controls(IGrid)  I used the scrollbars.. reisze until they are no longer displayed. In CJ I can't find scrollposition of bar visibility...    I've experimented with .rows(.rows.count-1).GetRect, but can't get it to work
 
Ideas (or code..) welcome.
 
Xtreme :SuitePro (ActiveX) version 13.1.0
Language: VB 6.0
Platform: WinXP/Win7(32+64bit)
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 21 March 2010 at 11:58pm
I found a solution, although it isn't pretty!

Assuming that you aren't already using SetCustomDraw with either of the measurement flags for other purposes, it is achievable. The main problem is that non-visible rows don't return values when you call GetRect, but you can use SetCustomDraw xtpCustomMeasureRow + xtpCustomMeasurePreviewItem, and then step through the rows to get all of the required heights.

There may be a better way to do this (I hope there is!), but this is what I came up with (put this code in a form with a ReportControl named ReportControl1):


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


Now that I think about it a bit more, you might be able to just loop through the report and use the Row GetRect method (and skip the whole SetCustomDraw event stuff), but this code should at least point you in the right direction.

Hope it helps!
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.