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

  • On-Demand eSeminar DevOps and Cloud are all the rage in IT, but the two terms relating process and computing aren't mutually exclusive. Join us to see how your movement into cloud changes the way you develop, deploy, test and manage, and how DevOps can actually be a good thing when coupled with cloud.

  • On-demand Event Event Date: May 18, 2015 While the idea of using facial and/or gesture recognition to create a modern, intuitive game seems attractive, some developers may want to leverage Unity 3D as a way to accelerate their development efforts. There are many different ways in which Intel and Unity Technologies have been working together to help speed the development of games with the Intel&reag; RealSense™ SDK (software developer kit). Check out this webcast to join a panel of experts as they …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date