cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically adding objects into header/footer of datawindows (grid issue)

Former Member
0 Kudos

I need to dynamically add a text object into the header and/or footer of all datawindow controls in my application. Most of these controls contain a grid style dataobject. The side effect of grids is that it chops the header and footer width to the first column's width in the detail band. This has always bothered me but now it produces an unacceptable visual.

If the text to be assigned to the new object is wider than can fit in the column it is chopped. Auto size height is not an option and is also visually unappealing. This object must not take away from the display area vertically. Ideally I would like the text to extend past the column boundary if necessary (like Excel does automatically). How can this be accomplished?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Russell,

Adding text in the header band is easy enough, except you add the text object to foreground instead of header:

dw_1.Modify ( 'CREATE text(band=foreground alignment="0" text="(C) Father XMAS" border="0" color="33554432" x="14" y="12" height="64" width="1399" html.valueishtml="0"  name=t_1 visible="1"  font.face="Tahoma" font.height="-10" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" background.transparency="0"  )')

Footer is more tricky.  If this is a standard footer for printing, you can still add it to the foreground band, but you need to figure out what the y position needs to be to print perfectly where you want it.  You should also leave vertical space (height) in the actual footer band.

In the past I have had success in added objects prior to printing and then destroying them afterwards.

If you need the footer on screen (not print preview), you can still do the same, but have to figure out the y position.

HTH

Lars

Former Member
0 Kudos

The text object has to display on the screen and print, basically wysiwyg. Foreground is not working. It chops the text to the width of column where I locate the object in grids.

text(band=foreground alignment="0" text="This is a test of a long text." etc, etc....

Former Member
0 Kudos

For example, I need the above text to display completely without resizing a column. The customer sees this work in Excel, which to them looks like a PB grid datawindow, natively and doesn't think this should be a big deal. Neither do I.

Former Member
0 Kudos

Are you adding the wide text in script using Modify()?  Or fighting the painter?

The datawindow painter allows you to change the layer to foreground in Position properties tab of the text object.  You are right that you can't change the width in the painter. The only way, other than creating the text in script is to edit the datawindow in the script editor and change the width property there.

You can edit the datawindow with a couple of limitations: 1) if the width happens to be at a column border, you can no longer resize it in the painter. 2) you still cannot modify the text object width property in the painter. 3) if you resize the column where the text object starts, then the x of the text object changes. (widen the column and the x moves similar to the right) All a bit fiddly.

Steps:

1) expand header band

2) move standard headers down

3) create text object in column 1, name it nicely

4) type the text

5) in the position tab change layer to foreground

6) save, close

7) edit source

😎 locate the item

9) change the width to more than it is

10) save, close

11) edit

you should see above

I am still in favour of modifying in script rather than using the pain ter.

Former Member
0 Kudos

Lars,

In my first post I said I need to add this text object dynamically. Reason being is most dataobjects are created from SQL syntax at runtime. Doing this through painter is not an option anyway.

If you create a report object then the datawindow turns to preview mode only. Therefore that also not an option. Wish Sybase would correct that.

'create text(band=footer alignment="0" text="' + a_s_text + '" border="0" color="33554432" ' ...etc...

If I use foreground I will have to write large additional code to locate and move the object to the correct visual location on the screen correct? I have lots of datawindows on screens, resizing going on, etc. The foreground doesn't move automatically I notice.

Former Member
0 Kudos

Hi Russell,

Sorry for the delay in responses.  I am in Australia and being 'new' to SCN my responses need to be moderated which invariably means next day...

Did understand you wanted to add dynamically, but couldn't quite figure why it didn't work for you.

You are right, you  do need code to move stuff down on the fly in the header band to make room.

In the below example I use a standard datawindow containing only objects in foreground and copy each object's syntax across verbatim. You can intercept and replace the text string with your a_s_text value before creating the object.  It illustrates an easy way to shift stuff dynamically.

string lsHeaderSyntax, lsCreate, lsError, lsObject[], lsObjects

datastore lds

integer liPos, liPosEnd, liXtraHeaderRoom, liXtraFooterRoom, lidx, liY

long lRow

// d_base is a simple datawindow containing text and computed values in the header band but layered in foreground

lds = CREATE datastore

lds.dataobject = 'd_base'

lsHeaderSyntax = lds.Describe ( 'datawindow.syntax' )

lsObjects = dw_1.Describe ( 'datawindow.objects' )

// first expand the header band to make room for objects in the header

// obtain required height from the d_base dataobject

liXtraHeaderRoom = integer ( lds.Describe ( 'datawindow.header.height' ) ) 

dw_1.Modify ( 'datawindow.header.height=' + string ( liXtraHeaderRoom + integer ( dw_1.Describe ( 'datawindow.header.height' ) )))

// indentify objects in the datawindow

liPos = 1

liPosEnd = pos ( lsObjects , '~t' )

DO WHILE liPosEnd > 0

          lsObject [ UpperBound ( lsObject[] ) + 1 ] = mid ( lsObjects , liPos , liPosEnd - liPos )

          liPos = liPosEnd + 1

          liPosEnd = pos ( lsObjects , '~t'  , liPosEnd + 1)

LOOP

lsObject [ UpperBound ( lsObject[] ) + 1 ] = mid ( lsObjects , liPos  )

// move all objects in header down

FOR lidx = 1 TO UpperBound ( lsObject[] )

          IF dw_1.Describe ( lsObject[lidx] + '.band' ) = 'header' THEN

                    liY = integer (dw_1.Describe ( lsObject[lidx] + '.y'))

                    dw_1.Modify ( lsObject[lidx] + '.y=' + string ( liY + liXtraHeaderRoom ))

          END IF

NEXT

// now "transfer" objects from d_base to the datawindow

liPos = POS ( lsHeaderSyntax , 'compute(name=' )

DO WHILE liPos > 0

          lsCreate = mid ( lsHeaderSyntax , liPos , pos ( lsHeaderSyntax , '~r~n' , liPos + 42 ) - liPos  )

          lsError = dw_1.Modify ( 'CREATE ' + lsCreate )

          liPos = POS ( lsHeaderSyntax , 'compute(name=' , liPos + 42)

LOOP

liPos = POS ( lsHeaderSyntax , 'text(name=' )

DO WHILE liPos > 0

          lsCreate = mid ( lsHeaderSyntax , liPos , pos ( lsHeaderSyntax , '~r~n' , liPos + 42 ) - liPos  )

          lsError = dw_1.Modify ( 'CREATE ' + lsCreate )

          liPos = POS ( lsHeaderSyntax , 'text(name=' , liPos + 42)

LOOP

at run time

You can maintain a standard datawindow in the painter without any clutter. 

For the footer there are challenges with the y position when you use foreground or background layer. It's a calculation to be done each time the datawindow resizes etc.  The d_base approach can be used for standard printing footers. You need to place the foreground objects way down so the fit the paper before merging.

HTH

Lars

Former Member
0 Kudos

Lars,

You've got some good ideas there.

My code is similar to yours. Get all the objects, parse to array, loop through and check the ones that are in the header, and add the height of the text object I created to it's Y value to slide it down. One thing flaky to handle is if there is already a foreground object in the header that needs to move also.

I'll have to look into your "transfer" method and see if I can use it in the future.

Thanks,

Russ

Answers (0)