image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

Alternating Row Colors (iTunes ListBox Redux) by Seth Willits
10-01-05

Printer Version




iTunes ListBox
Over three years ago, Erick Tejkowski posted a tutorial on alternating row colors to get the same style as iTunes. Times have changed apparently and his project no longer is... optimal. Now while the current solution is very simple, maaany people still ask how to do it, and I actually had someone ask me this morning so I figure I might as well post the answer. You know what they say, if one person asks, several more people have the same question...

Create the Class
Because code reusability is a good thing, we're going to create a simple class to do this. Add a ListBox subclass named "ARListBox". Add one property, "AlternateRows as Boolean" and make sure it is Public. The code to alternate the rows is:

Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
  if AlternateRows and row mod 2 = 0 then
    g.ForeColor = RGB(237, 243, 254)
    g.FillRect 0, 0, g.Width, g.Height
  end if
End Function

row mod 2 will equal 0 on every other row (0 mod 2 is 0, 2 mod 2 is 0, 4 mod 2 is 0...) so that's our switch for alternating between blue and white. AlternateRows is a boolean property which can allow you to use the same class for both alternating and non-alternating lists. To make it show up in t he properties list in the window editor, go to the project tab and Right/Control-Click on the ARListBox class and select "Window Editor Behavior..."



Here you'll see a list of the public properties of the ARListBox class and checkbox next to each one. If the box is checked, that property will be displayed in the properties list in the window editor. This is the new home of the "Show in Properties List" checkbox that was in REALbaisc 5.5 and earlier when you created a property. So check that...



...and now when you add an ARListBox to the window in the window editor, you'll see the AlternateRows property way down at the bottom of the list. Check that box to have the alternating colors appear.



After that, we just need a little bit of test code that will just add rows to the listbox to test it.

Sub Open()
  dim i as Integer
  for i = 1 to 15
    me.AddRow "Row " + str(i)
    me.Cell(i - 1, 1) = "Cell (" + str(i) + ", 1)"
    me.Cell(i - 1, 2) = "Cell (" + str(i) + ", 2)"
  next
End Sub



Finished
Like I said, it's very simple, but many people do ask how to do this. If you already knew, congrats! If you didn't, congrats! Now you do! One thing to note is that the alternating rows go all the way to the bottom of the list even though there aren't actual rows there. This is a new feature in REALbasic 2005. In 5.5 and earlier the CellxPaint events were only called for each row in the listbox, but now it's called for each potential row that would fit in the visual bounds of the list. Handy! Download the project.




Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]