Smart List Box with Formatting and In-Line Buttons

The Smart List Box lets you define multiple vertical columns and add font controls to a standard list box facility.

As shown in the screen captures, you can specify the forecolor and backcolor for each column, as well as the font characteristics. You also can specify font characteristics for each cell; that is, the rows do not all have to look the same. You can specify headers and footers, as well; they need not have the same text. Vertical and horizontal scroll bars are automatically generated when necessary. The font codes used are compatible with HTML font codes.

The standard properties and methods still work. So, you can AddItem and RemoveItem, and use ListIndex and ListCount as you would with a normal VB List Box. When you use AddItem, you separate the data for each column with a TAB character [CHR$(9)].

You can specify an HTML font code (colour, bold, italics, and so forth), if you wish, for each piece of column data.

You can have one or more buttons in each cell; when the button is pressed, a ButtonClick event occurs in the calling program. You can specify the alignment of buttons independently of the alignment of the text in the cell. The SmartListBox maintains two ImageLists internally, containing the pictures to be displayed normally. When the button is pressed, a button may be partially displayed and still function as a button. Hidden buttons (due to the column width being such that the button is left or right of the displayed area) are disabled. Pictures are placed into the SmartListBox with the AddImage method, and then referenced with a code similar to an HTML code; you can optionally add an alignment code after the picture reference to force the picture to align at the bottom, centre, or top of the cell in which it is displayed. The picture reference may be a number or a name.

Row and column separator colours can be specified, as well as the thickness of the lines. Unlike the normal VB ListBox, you can change the Style property from Normal to CheckBox (or vice versa) at run time. You also can change the height of any or all lines.

You can set the AllowDuplicates property that will or will not cause an error if a line with a duplicate key (data in the sort column) is entered.

But wait, there's more!

There is a SortDone event that is fired when sorting is complete. This lets you re-paint line background colours, for example, in the case where you have alternating backgrounds and the sequence is messed up by a column sort.

This program uses my automated debugging technique (basically a replacement for Debug.Print). For details, see my Testing Concepts Web site, and click on Zero Defect Programming. By setting the global variable WantDebug to TRUE, the program will tell you what it is doing, creating a trace log in the C:\ root directory.

Several test harnesses are included in the source code file. Each test harness exercises features of the SmartListBox and lets you play with it to understand how the functions work.

Check box style can be turned on or off at run-time:

An error optionally can be raised if duplicate lines are entered:

Macros can be used in the footers to show count, average, minimum, maximum, and total.

Several test harnesses are included, ranging from simple to complex. The complex one lets you experiment with most properties, and play with using buttons; each button may have an alignment code that may be different from the text alignment.

About the Author

Doug Anderson

VB6 programmer, interested in OCR, list processing, educational software, handling Thai and other languages.



  • Splendid..

    Posted by viren on 10/17/2014 10:49pm

    I learned a lot

  • Dynamically adding listbox

    Posted by shashwata on 07/05/2006 02:33am

    Hello, can anybody help me with regard to adding a list box dynamically when we click a button? i'm using jsp as front end, mysql as a back-end thank u, shashwata

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds