1. Kari Paukku
  2. PowerBuilder
  3. Saturday, 29 October 2022 02:48 AM UTC

Hi,

I know how to get the width of a data window from columns, e.g. using code like this

FOR I = 1 To Long(This.Describe("DataWindow.Column.Count"))
  IF This.Describe("#" + String(I) + ".Visible") = "1" THEN
    TotalWidth = TotalWidth + Long(This.Describe("#" + String(I) + ".Width") ) 
  END IF
NEXT

But this has the problem that it excludes e.g. computed columns.

Is there a way to get the width using the column headers?

Thanks,

kp

 

 

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Saturday, 29 October 2022 04:02 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi, Kari -

The "Objects" property of a DataWindow contains a tab-delimited list of the names of all of the DWObjects contained in the DW's Data Object:

ls_objects = dw_control.Object.DataWindow.Objects

By parsing each of the names from this string, you can use Describe to determine each DWObject's type:

ls_objecttype = dw_control.Describe(ls_objectname + ".Type")

Refer to the PB Help topic named "Type property (DataWindow object)" for the list of all DWObject types returned by this property.

Instead of summing the widths, I suggest instead examining the Width of the visible DWObjects added to its X-position, giving its right-most X-position, and keeping track of the largest of these values. That should tell you the effective DW's "width".

Please note a couple of things: (1) I'm pretty sure that columns that use autosize width do not report the "live" (runtime) width, only the width of the column as defined in the painter, and (2) line objects do not have a Width property... they instead have X1 and X2 properties that are the X-position of the line's endpoints.

Best regards, John

Comment
There are no comments made yet.
Kari Paukku Accepted Answer Pending Moderation
  1. Monday, 7 November 2022 14:26 PM UTC
  2. PowerBuilder
  3. # 1

Here is the revised code.

 

Long I
Long TotalWidth

String ls_objects
String ls_objecttype
String ls_objectname
String ls_Band
Long p
Long TextX, TextWidth
Long MaxX = 0

IF This.dataobject = "" THEN
RETURN 0
END IF

ls_objects = This.Object.DataWindow.Objects

 

p = 1

do while ls_objects<>'' AND p > 0
    p = pos(ls_objects,'~t',1)
    ls_objectname=left(ls_objects, p - 1)


    ls_objecttype = This.Describe(ls_objectname + ".Type")
    ls_Band = This.Describe(ls_objectname + ".Band")

    IF Lower(ls_objecttype) = "text" AND Lower(ls_Band) = "header" THEN

       IF Long(This.Describe(ls_objectname + ".visible")) = 1 THEN

        TextX = Long(This.Describe(ls_objectname + ".x"))
        TextWidth = Long(This.Describe(ls_objectname + ".width") )

         IF TextX + TextWidth > TotalWidth THEN
            TotalWidth = TextX + TextWidth
         END IF

       END IF

   END IF

   ls_objects=Mid(ls_objects, p +1)

loop

 

IF This.vscrollbar THEN
   TotalWidth = TotalWidth + 80 //Scroll Bar Width
END IF


RETURN TotalWidth

 

Comment
There are no comments made yet.
Kari Paukku Accepted Answer Pending Moderation
  1. Friday, 4 November 2022 03:25 AM UTC
  2. PowerBuilder
  3. # 2

John,

thank you. I did as you suggested and it works fine. Below is my code for others as a starting point.

Kari

String ls_objects
String ls_objecttype
String ls_objectname
String ls_Band
Long p
Long TextX, TextWidth
Long MaxX = 0

ls_objects = dw_1.Object.DataWindow.Objects

messagebox("ls_objects", ls_objects)

p = 1

do while ls_objects <> '' AND p > 0
  p = pos(ls_objects,'~t',1)
  ls_objectname=left(ls_objects, p - 1)


  ls_objecttype = dw_1.Describe(ls_objectname + ".Type")
  ls_Band = dw_1.Describe(ls_objectname + ".Band")

  IF Lower(ls_objecttype) = "text" AND Lower(ls_Band) = "header" THEN

    TextX = Long(dw_1.Describe(ls_objectname + ".x"))
    TextWidth = Long(dw_1.Describe(ls_objectname + ".width") )

    IF TextX > MaxX THEN
      MaxX = TextX
    END IF

  END IF

   ls_objects=Mid(ls_objects, p +1)

loop

MessageBox("MaxX", MaxX)
MessageBox("TextWidth", TextWidth)
MessageBox("Total Width", MaxX + TextWidth)

Comment
  1. Kari Paukku
  2. Friday, 4 November 2022 07:25 AM UTC
Thanks, I make the calculation to include 80 PBU and mark the ticket resolved.

kp
  1. Helpful
  1. Miguel Leeuwe
  2. Friday, 4 November 2022 11:30 AM UTC
There's another thing missing. It's possible that you have a column which doesn't have the highest X position, but due to a big Width value might still determine the maximum width of the dw. So what you have to do, is search for the biggest value of maxX + width. That would determine the width of your dw.

regards.
  1. Helpful
  1. Kari Paukku
  2. Friday, 4 November 2022 11:35 AM UTC
ok, thanks. I amended my code accordingly.

kp
  1. Helpful 1
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.