Welcome!

PowerBuilder Authors: Dan Joe Barry, Carmen Gonzalez, Ian Thain, Yakov Werde, Paul Slater

Related Topics: PowerBuilder

PowerBuilder: Article

Fixing Ugly Grid Borders

Fixing Ugly Grid Borders

It's an aesthetic thing. When you click on a grid DataWindow label and change an attribute, it acquires what are formally termed UGBs - Ugly Grid Borders. They appear between the labels in the grid header. The vertical lines are thin or thick. Inconsistency! Thick borders! Yuck! Figure 1 illustrates the problem.

There are thick borders between the Nickname and Last Name labels and between the Company and Nickname columns; there are thin borders between the Company and Nickname labels and between the Nickname and Last Name columns.

Figure 2 shows the same DataWindow with the UGBs fixed.

All the borders are thin in Figure 2, which looks a lot better.

The UGB problem is characteristic of 3D objects on grids. The detail columns in the figures are 3D lowered. You don't have to worry about UGBs if all your DWO objects are flat.

With PB6 and earlier releases it was easy to fix the UGBs manually: select the left-most column label, hold down the shift key and press the right arrow key to select all the labels, then right-click that left-most label and select Bring to Front from the popup menu.

With PB7 (and later) that trick stopped working: you can't fix all the labels in one operation. With recent versions of PowerBuilder, you have to fix one label at a time, going left-to-right: right-click the label, Bring to Front, right-click the next label, Bring to Front, etc., for every label on the grid; ditto for columns. It's a pain.

This article presents a programmatic solution to UGBs. It turns out that the problem is how lines are ordered in the DWO syntax. The code presented in this article fixes the DWO syntax, banishing those embarrassing UGBs. Once you're set up, you can fix all the UGBs in your application in a few minutes. It becomes part of the build process, so your programmers can ignore the problem and your users are forever spared UGBs. A utility for fixing UGBs is provided.

Looking at the Syntax
In DWO syntax, labels correspond to text objects. If you look at the exported DataWindow syntax, before and after fixing the UGBs, you'll find that the order of the text object declarations has been changed. The first part of the text object syntax line looks like:

text(band=header S x="9" y="8"S

It turns out that the critical part of the syntax is the x attribute, x="9" in the line above. When a grid has UGBs, the text lines are not in x-attribute order. The following shows how the text object declarations are ordered when the UGBs have been eliminated:

text(band=header S x="9" y="8"S
text(band=header S x="338" y="8" S
text(band=header S x="3470" y="8" S

The x attributes are 9, 338, and 3470 - monotonic ascending order.

Here's what I infer: PB instantiates DWO objects, processing the DWO syntax in top-to-bottom order, and the UGBs appear when the objects' order of instantiation is not uniformly left-to-right.

The solution is to reorder the 3D-object syntax lines according to their x attribute.

The Code
The main function is f_fix_ugly_grid_borders(). It takes a DataWindow control (DWC) upon which the target DataWindow object (DWO) appears. Here is a high-level description of f_fix_ugly_grid_border():

  • Confirm that the DWO is a grid
  • Put the DWO syntax into a syntax string array
  • Break all the "text" object lines into another array
  • Sort the text array by the x attribute
  • Put the sorted text lines back into the syntax array
  • Do the same order-lines process for the detail column objects
  • Accumulate the syntax array into a DWO syntax string
  • Do a LibraryImport() to put the fixed DWO into its PBL

    Another function is called during the process above: f_get_dw_syntax_as_array() takes the DWC and returns the DWO's syntax as an array. This function is needed because DWO syntax sometimes wraps lines:

    text(name=department_t band=header ...
    Rule in English" )

    After the syntax has been placed in an array, the array has to be processed to move the wrapped bits to the end of the preceding array element, e.g., putting "Rule in English" at the right end of the "department_t" line. Otherwise, those bits would be lost when the lines are reordered. Another function processes the PBLs that make up the application. It passes through the PBLs, doing a LibraryDirectory() on each to get the DataWindow objects contained therein. It then sequentially passes those DWOs to f_fix_ugly_grid_borders(). It takes about five minutes to fix a couple hundred grids.

    You can download a small utility from www.sys-con.com/pbdj/sourcec.cfm that will apply these functions to fix up your application's grids. The source code is included as well.

    Summary
    Since we took up PB7 and later versions, most of us have had to live with Ugly Grid Borders, since they were so cumbersome to fix manually. The technique presented here will make it easy for you to eradicate them. Download the utility and say goodbye to the heartbreak of UGBs!

    A final suggestion: f_fix_ugly_grid_borders() can be adapted so it can be applied at runtime. This is useful if your application encourages users to drag grid columns around, e.g., to make columns on wide DataWindow objects visible without scrolling to the right. UGBs always appear when 3D grid columns are reordered at runtime. If you provide users with a means to save their preferred column order for later restoration, you can apply f_fix_ugly_grid_borders() right after the modify() that restores the user's preferred column order..

  • More Stories By Hoyt Nelson

    Hoyt Nelson is an independent contractor, a 10-year PowerBuilder veteran, and father to the amazing Nelson, Kent, Emma, and Molly (Hi, kids!).

    Comments (1) View Comments

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    Most Recent Comments
    Michael Cornelissen 10/15/03 02:39:28 AM EDT

    Yesterday I received the new PBDJ. I was delighted to see this ugly Grid issue fixed: it already bothered me for years.

    I'm a little bit disappointed that the source file is not available right now.

    Is that a mistake and will it be available shortly?

    Regards,

    Michael Cornelissen
    Netherlands