This chapter's code implements two features of the Library Project: (1) a simple helper class used with
ComboBox controls to manage text and data; and (2) a set of generic forms used to edit lookup tables in the Library, such as tables of status codes.
In Visual Basic 6.0 and earlier,
ComboBox controls included two primary array-like collections:
List (used to store the display text for each item) and
ItemData (used to store a 32-bit numeric value for each item). The
List array was important to the user since it presented the text for each item. But many programmers depended more on the
ItemData array, which allowed a unique identifier to be attached to each list item.
cboMonth.AddItem "January" cboMonth.ItemData(cboMonth.NewIndex) = 1 cboMonth.AddItem "February" cboMonth.ItemData(cboMonth.NewIndex) = 2 ... cboMonth.AddItem "December" cboMonth.ItemData(cboMonth.NewIndex) = 12
Later, after the user selected a value from the list, the numeric ID could be used for database lookup or any other designated purpose.
nMonth = cboMonth.ItemData(cboMonth.ListIndex)
The bad news is that neither
ItemData exists in the .NET variation of
ComboBox controls. The good news is that both are replaced with a much more flexible collection:
Items collection stores any type of object you want: instances of
Animal, or even
Superhero, and you can mix them within a single