Currently Being Moderated

On a long list of data, it’s easy for the user to lose track of which row they’re looking at. This can be alleviated a bit by the use of alternating colors on each row, but even that can be trying. Another option is to subtly highlight the row that the mouse is hovering over. But how can we do that in PowerBuilder?

 

There are three ways to highlight a row. The first way is to use SelectRow(); unfortunately, this call gives you absolutely no control of the look of the highlight and is typically used for actual row selection instead of as a focus indicator. The second method for highlighting a row is to change the background color of the detail band. The third method is to use a rectangle object placed behind every column and stretching across the width of the row. The processes for these latter two methods are nearly identical, so I’ll explain row highlighting using the detail band.

 

The first thing you need to do is to pick a color that you’ll use for your focus indicator. I chose the all-to-lovely fuchsia. Open your DataWindow in the DataWindow painter, set the background color of the detail band to fuchsia, then change the transparency to 100% (completely transparent). Save and close; this is the only change you need to make to your DataWindow.

 

Now open up the window that this DataWindow is displayed on. We’re going to need to keep track of the row that’s currently given focus, so declare an instance variable of type Long. I prefer to call mine il_PreviouslyFocusedRow. Now, right-click on the DataWindow control and choose “Script”. In the event drop-down, choose “(New Event)”. Call this event “mousemove” and map it to Event ID “pbm_dwnmousemove”. This event script will be what controls the magic.

 

What we’re going to do is to change the transparency of the row that the mouse is over so that the color bleeds through. This can only be done through an expression and that expression will have to change each time they hover over a new row. Here’s the short and sweet script:

IF Row <> il_PreviouslyFocusedRow THEN

   THIS.Modify (‘datawindow.detail.transparency=”100~if(getrow()=’ + String (Row) + ', 75, 100)"')

   il_PreviouslyFocusedRow = Row

END IF


Now for the cool part: What if we could do this for both the row and column in a crosstab DataWindow? Let’s make that happen, too!

 

Open up your crosstab DataWindow in the painter. Make sure your background on your detail band is set. We’re going to do the same to the background of the columns. Select the column, change the background color (to fuchsia!) and make it completely transparent. Save and close, and go back to the window painter.

 

We’ll need another instance variable to track the previously highlighted column. It’s a string value which I tend to call is_PreviouslyFocusedColumn. Our code to highlight the column also resides in the MouseMove event, so let’s add some script there.

String ls_Col

ls_Col = String (dwo.Name)

IF ls_Col <> is_PreviouslyFocusedColumn THEN

   IF PreviouslyFocusedColumn <> 'datawindow' THEN Modify (PreviouslyFocusedColumn + '.background.transparency="100"')

   IF ls_Col <> 'datawindow' THEN Modify (ls_Col + '.background.transparency="75"')

   PreviouslyFocusedColumn = ls_Col

  END IF

 

What’s with this check against a value of ‘datawindow’? With column sizing turned on, you’ll notice that the mouse cursor changes to a resize icon when it is between two columns. When this happens, the MouseMove event’s dwo argument references the datawindow and not either of the two columns. Because of that, the modify statements fails and you end up with every column becoming highlighted. This check prevents that. Go ahead and run it! See what happens!

 

It didn't work, right? Did all kinds of funky stuff? That’s because normally, each column on the screen is just a reference to the single data column in the buffer. We can change that, though, by putting the DataWindow into static mode. Once we do that, each column becomes a true and independent column. So go back to your window and navigate to the Open event. Add this single line of code:

dw_1.Modify (“datawindow.crosstab.staticmode=yes”)


You now have row and column highlighting as you move your mouse around!

Comments

Actions

Filter Blog

By author:
By date:
By tag: