Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL
Expertise: Beginner
Mar 21, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

How can I dynamically add or delete entries from a list box?

How can I dynamically add or delete entries from a list box, popup list or combo box?

List boxes, popup lists and combo boxes all use the Translation property. The Translation property gives all of these list-type objects the ability to display one value to the user while using a different value for the selection. For instance, a combo box could display the name of an employee, while the actual Value property is the employee's identification number.

You can set the display and internal values for a list-type object by assigning database columns for the display and internal values, by assigning an SQL statement to the Translation property that returns a column for the display and internal values, or by creating a text list where the display value and the internal value are each listed on a separate line with an "=" sign between them, as illustrated below.

Aaron = A
Bobby = B
Cathy = C

The techniques described below allow you to add entries or delete entries from list-type objects that use a value list in the Translation property.

To dynamically add entries to a list-type object, you can dynamically reset the Translation property of the object. In the code example below, the display value, represented by the vsDisplay variable, the "=" sign and the internal value, represented by vsValue, are concatenated onto the end of the Translation property for the lstSample list box.

DIM sNewLine As String

sNewLine = CHR(13) & CHR(10)

lstSample.Translation = lstTranslation & sNewLine & &

       vsDisplay & "=" & vsValue


Before the values are added to the Translation property, a new line character and a carriage return character are added to the end of the property to indicate a new entry is about to begin. The CHR() function assigns the value of the ASCII character for the characters to the sNewLine variable, which is added to the Translation property before the new values.

Setting the Translation property will cause the list-type object to automatically re-populate itself.

You can also use string manipulation methods to delete values from the Translation property. You would find the current Value of the list-type object in the Translation string, find the following the value, find the preceding the value and then reconstruct the property without the entry for the value.

Note: In version 1 of Oracle Power Objects, a bug causes a list box to not completely clear a list box once you delete the final entry in the Translation property.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



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