ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5


5 - And Then Some

All this makes CList useful enough - however, it can do much more. The key is the open nature of the code. Remember that the parent CList class only needs to know the number of items in a list - your child class deals with the actual data and row height. This points up some interesting possibilities:

  • Your constructor could easily be passed a structure array, an object array, or any form of list, not just a string array, since it's your DrawRow() function that interprets it.
  • In fact, you don't even need to pass data. For a list where the choices can be computed (like picking from one to ten), the row number could be used to generate the display text.
  • What GetRowHeight() returns can be on a row-by-row basis, allowing you to have a variable sized list box, such as for font size selection.
  • DrawRow() can draw anything. You are told the rectangle you have to fill, and what index the row corresponds to - what you draw is up to you.

To illustrate some of these variations, the example source code (eg_6.zip) creates and displays three different modal list box dialogs:

  1. The string list in action using an array for string data
  2. A list box that synthesizes the data on the fly, using the row number. This code can be useful where the choices follow a calculated sequence.
  3. A box demonstrating two techniques, the passing of a structure, and the display of different types of data. It shows a list of arrows and corresponding descriptive text. Using a structure keeps these items organized, and makes maintenance easier.

The download also includes a SEB file for the impatient, but I encourage you to review the code to get comfortable with the CList class and its varied progeny - it might spark some creative variations on your part. A final point to remember is that in each case, little or no memory is used besides the original data. On a computer with limited memory, this is a very good reason that virtual list boxes should be a important addition to your programming arsenal.

Previous Section


Copyright © 2001-2006 ebmDevMag.com - Legal Notice