WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Editor version 6.2
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Reportview Set Column Width

 Keywords: Reportview Set Column Width Header Data Size Length Dialog 

Question:

Can you provide a code sample to dynamically resize columns in a Reportview control in a WIL Dialog, based on the heading and data in each column?

Answer:

#DefineSubRoutine MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,MyDialog_ChangeInfo)
      MSG_INIT=0                    ; The one-time initialization
      MSG_BUTTONPUSHED=2            ; Pushbutton or Picturebutton
       ;DialogControlSet / DialogControlGet Constants
      DC_RVCOLHEAD=20           ; REPORTVIEW
      DC_RVCOLWIDTH=21          ; REPORTVIEW
      DC_RVADDCOL=22            ; REPORTVIEW
      DC_RVREMOVECOL=23         ; REPORTVIEW
      DC_RVMATCHCOL=24          ; REPORTVIEW
      DC_RVCANCELEDIT=25        ; REPORTVIEW
      DC_RVCHECKEDROWS=26       ; REPORTVIEW
      DC_RVJUSTIFY=27           ; REPORTVIEW
      ;Return code constants
      RET_DO_CANCEL=0           ; Cancels dialog
      RET_DO_DEFAULT= -1        ; Continue with default processing for control
      RET_DO_NOT_EXIT= -2       ; Do not exit the dialog
      ON_EQUAL = @TRUE                                         ; Initialize variable ON_EQUAL
      Switch MyDialog_Message                                  ; Switch based on Dialog Message type
         Case MSG_INIT
            ; Set report column width to header or data width, whichever is larger
            DlgCtrlParmWidth = ''
            DlgCtrlParmJustify = ''
            y = ArrInfo(Your_Array, 2)
            For x = 1 To y
                v1 = '-1' ; Set default to '-1' = data width | '-2' = header width
                v2 = 0 ; Set default to 0 = left justify | 1 = center | 2 = right justify)
                i1 = Your_Array[0,x-1] ; get header row values
                i2 = Your_Array[1,x-1] ; ; get data row values
                l1 = StrLen(i1) ; char length of header value
                l2 = StrLen(i2) ; char length of data value
                If l1 > l2
                 v1 = '-2'
                 v2 = 1 ; header is wider than data value so set width to header and center data value
                EndIf
                DlgCtrlParmWidth = ItemInsert(v1, -1, DlgCtrlParmWidth, " ")
                DlgCtrlParmJustify = ItemInsert(v2, -1, DlgCtrlParmJustify, " ")
            Next
            DialogControlSet( MyDialog_Handle, "ReportView_1", DC_RVCOLWIDTH, DlgCtrlParmWidth) ; DC_RVCOLWIDTH = 21
            DialogControlSet( MyDialog_Handle, "ReportView_1", DC_RVJUSTIFY, DlgCtrlParmJustify) ; DC_RVCOLWIDTH = 27

            Return(RET_DO_DEFAULT)

        Case MSG_BUTTONPUSHED                                 ; ID "PushButton_Close"  Close
           Return(RET_DO_DEFAULT)

      EndSwitch                                                ; MyDialog_Message
      Return(RET_DO_DEFAULT)
   Drop(x,y,v1,v2,l1,l1,DlgCtrlParmWidth,DlgCtrlParmJustify)
#EndSubRoutine                                                ; End of Dialog Callback MyDialogCallbackProc


filename = AskFilename("CSV FIle", DirScript(), "CSV Files|*.csv", "", 1 )
Your_Array = ArrayFileGetCSV( filename, 0)
MyDialogFormat=`WWWDLGED,6.2`
MyDialogCaption=`WIL Dialog 2`
MyDialogX=002
MyDialogY=059
MyDialogWidth=594
MyDialogHeight=119
MyDialogNumControls=002
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,154|203|252`
MyDialogConfig=0
MyDialog001=`551,099,026,012,PUSHBUTTON,"PushButton_Close",DEFAULT,"Close",1,10,160,DEFAULT,DEFAULT,"255|255|255"`
MyDialog002=`013,013,564,082,REPORTVIEW,"ReportView_1",Your_Array,DEFAULT,DEFAULT,20,3145728,"Microsoft Sans Serif|5632|40|34",DEFAULT,"255|255|255"`
ButtonPushed=Dialog("MyDialog")

Article ID:   W18513
Filename:   Reportview Set Column Width.txt
File Created: 2014:06:03:07:43:24
Last Updated: 2014:06:03:07:43:24