Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting lines in Tableframe 2

Status
Not open for further replies.

LWB

Technical User
Feb 4, 2003
95
0
0
US
I have a form that contains a tableframe. I want to be able to change the background color of each record in the frame based on the value of one of the fields. It will be one of four colors depending on which of four values appear in a calculated field. I can make the background colors change, but when the table scrolls the background color doesn't move with the record.

I can't figure out where to put the code to make it work. Or maybe I'm going about it the wrong way.

Lynn
 
You need to add the following to the Var method for your tableFrame:

Code:
Var
  uiRecord        UIObject
endVar

Add the following two methods to the tableframe events Open and Action:

Code:
method open(var eventInfo Event)
  doDefault
  uiRecord.attach(self'firstRow)
  self.home()
   ; or I sometimes use self.end()
   ; if I want to start at the end of the table
endmethod

Code:
method action(var eventInfo ActionEvent)
  if eventInfo.actionClass() = DataAction then
    uiRecord'color = Transparent
    doDefault
    uiRecord.attach(fldDate'containerName)
     ;change fldDate to some field in your tableFrame record
    uiRecord'color = Yellow
  endIf
endmethod

Then attach the following code to the open event for the record object in your tableFrame:

Code:
method open(var eventInfo Event)
  self.color = Transparent
endmethod

The only other thing to watch is to not name the record object in your table frame, leave it with the Paradox generated name.


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Mac,

Thanks. That does a great job of highlighting the first record in the table, but I actually want to color every line (record) in the table based on the value (a string) in #Field508 (I didn't change the name!) So as the user scrolls through the table each record is colored appropriately.

The table contains project budget by project number and I want to color each record based on what type of project is is(four types).

Lynn
 
You know, I read your post but I completely got tunnel vision with my response - sorry. I don't know how to do what you want.

(Off the top of my head) - It might be easier to have 4 small tableframes or MROs on the form linked to the same table and use setRange() to restrict the data shown in each one based on the four project types. Then you could color the background of each tableframe or MRO.

The MROs might make it look a bit less cluttered.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Mac,

I tried putting the code on the record under action, but I had to actually select the record to get the color to change and scrolling beyond the initial set of records visible resulted in some records ending up with the wrong colors (unless I selected them again).

The code you provided, if I scroll to the point the hightlighted record leaves the top the highlight jumps to the bottom and scrolls up to the top again.

I do want the records in the order they are in, so I don't want 4 tableframes. At least not on this particular form.

I thought this would be easy and I was just missing the obvious!

Lynn
 
The only other thought I have is that you might add an image field that contained a small jpeg of a colored box or icon. Sorry I couldn't be more help.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Lynn,

This is actually one of the hardest things to do with Paradox, primarily due to the event model and the way it works.

One of the original Paradox Product Managers (from the Ansa days) is the one who figured out how to do this and you can find a slightly updated version of his code at
While I haven't posted his original article (to avoid violating the copyright), the code still works with current versions of Paradox.

In your case, you'll want to calculate HL_COLOR before assigning it. So you'll probably want to slip your calculation into the code after the default behavior of the DataAction action handler.

Hope this helps...

-- Lance
 
Lance,

The code you referenced works great! I put my check for the value of the one field to determine color after the doDefault in the action method (of the tableframe). So now the highlighted color of the selected record is what I want.

I can see that this code will be useful in a variety of places. Thanks.

However, what I was really trying to accomplish still eludes me. I don't really care about highlighting the record that has the current focus, but coloring each record according to the value of one of the fields. I don't want the color to change unless the value of that Field changes (which it will not, this form is just to view data, not change it).

It seems to me that a modification of the code you provided will do it, but so far I haven't figured it out.

Any ideas?

Lynn
 
Lynn,

This is a hard one to pull off, primarily because of the event model and how it behaves. In my experience, this sort of effect needs some careful planning, but once that's been done, it becomes fairly straightforward.

To demonstrate, let's assume we're creating a form containing the traditional sample Customer and Orders sample tables. Furthermore, Orders is a detail table of Customer, so you're showing a summary of the customer's orders while editing their address information.

Now, let's assume you want each order's record to be colored according to the value in the Total_Amount field, thereby highlighting the largest orders (and the most valuable customers).

If you look at this from a purely operational point of view, you're really coloring the record based on an individual field value. We also know that it's very possible to interfere with the event model by placing code into the middle of thwat's called the recalc/repaint cycle.

So, we're looking for an event that fires after the Total Invoice field has been completely updated and drawn. NewValue is an excellent candiate in this case because we're designing a side-effect; we're not validating the value. We need to make certain we do our tyhing after the internal behavior has run, so we'll need a doDefault to avoid interfering with the recalc/repaint cycle.

Given all of this, here's one way to achieve the effect:

Code:
method newValue(var eventInfo Event)
var
   liNewColor  LongInt
   uio         uiObject
endVar

   doDefault
   uio.attach( container.FullName )

   switch
      case self.value > 50000 : liNewColor = Red
      case self.Value > 25000 : liNewColor = Yellow
      case self.Value > 10000 : liNewColor = Green

   otherwise : liNewColor = LightBlue

   endSwitch

   uio.Color = liNewColor

endMethod

You'll note that I'm changing the color of object containing the Total_Invoice field object. Thus, my code suports any number of Total_Invoice field objects.

Also, note that I refer to the container using its full name, which includes the default (or "noise") names Paradox assigns to each record object in the table grid.

(By the way, if you're looking to validate values (that is, determine if you want to accept them before they're saved, the best place I've found is the ChangeValue event before the default behavior has fired.)

Try restating your problem in this fashion. Look for a field that changes value based on your needs and then add similar code to change that object's container.

I believe you'll find this a more successful approach in the long run.

Hope this helps...

-- Lance
 

Lance,

Wow! You are wonderful! The code does exactly what I want to do!

I really appreciate you and the other experts that so generously provide their time and advice to the rest of us!

Thanks for the info about highlighting the active record also - I plan to make good use of that in other forms.

Thanks! :)

Lynn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top