![]() |
|
Published 1998-07-01 Printer-friendly version
NOTE: Clarion Magazine was not able to obtain an archive of the original source code for this article. If you have the source, we'd very much appreciate it if you would email it to us so we can post it for other readers.
I want to display rows in a listbox in alternating colors or "greenbar paper" style. In other words, I want every other row to have a grey background. I thought I could use the BrowseBox control template's conditional colorization and modulus division, but due to the BrowseBox page-loading this does not work. Do you have any suggestions?
Yes, I have two suggestions--one is bad; the other good. First the bad suggestion: You could get a piece of transparent film with stripes on it and tape it to your monitor. But, that would require installation by all your users and you would have to ship tape with all your installation disks, so let's take another approach.
You are correct in your assessment that the BrowseBox's page-loading scheme must be handled for this to work properly. . You gain many benefits from page-loading, but with these benefits comes some responsibilities when coding.
Color attributes are stored in the QUEUE used as the FROM attribute of the LIST. Using the built-in Conditional Colorization works whenever a complete "page" of records replaces the current values stored in the QUEUE, but scrolling one-by-one will cause it to fail. What you need to do is loop through the QUEUE every time a NewSelection event occurs (every time the user manipulates the list control). This adds very little overhead because the queue is in memory and never contains more than a page of records (in most cases twenty or so)
This is a good example of a time when deriving a method in the ABC classes is the best approach. Clarion 4 and the ABC templates allow you to do this easily.
From the Window Formatter:
This enables the Data Embed and Code Embed buttons.

LOOP I# = 1 to RECORDS(SELF.Q)
GET(SELF.Q, I#)
ASSERT(NOT ERRORCODE())
EXECUTE (I# % 2) +1
BEGIN
! Apply Normal background color to every field
! displayed in LIST on alternating rows
SELF.Q.MEM:MemberNumber_NormalBG = COLOR:Silver
SELF.Q.MEM:LastName_NormalBG = COLOR:Silver
SELF.Q.MEM:FirstName_NormalBG = COLOR:Silver
END
BEGIN
! Reset Normal background color to every field
displayed in LIST on alternating rows
SELF.Q.MEM:MemberNumber_NormalBG = -1
SELF.Q.MEM:LastName_NormalBG = -1
SELF.Q.MEM:FirstName_NormalBG = -1
END
END
PUT(SELF.Q)
ASSERT(NOT ERRORCODE())
END
BRW1.Greenbar !Call Method to apply alternating colors
BRW1 is the name of the BrowseBox object. We call it explicitly (instead of using the SELF.method convention because we are calling it from outside the object).
POST(EVENT:NewSelection,?Browse:1)
This ensures the colorization occurs when the user drags the thumb up or down. ScrollDrag does not automatically produce a NewSelection Event.

Your alternating colors should appear as you want. So throw away your transparencies and highlighter pens!

Submit your questions to DrD@clariononline.com.
Copyright © 1999-2008 by CoveComm Inc. All Rights Reserved. Reproduction in any form without the express written consent of CoveComm Inc., except as described in the subscription agreement, is prohibited.
Clarion Magazine ISSN 1718-9942
One year: $189
(includes all back issues since '99)
Renewals from $139
Two years: $289
Renewals from $239