devxlogo

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

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

Question:
How can I dynamically add or delete entries from a list box, popuplist or combo box?

Answer:
List boxes, popup lists and combo boxes all use the Translationproperty. The Translation property gives all of these list-typeobjects the ability to display one value to the user while using adifferent value for the selection. For instance, a combo box coulddisplay the name of an employee, while the actual Value property isthe employee’s identification number.

You can set the display and internal values for a list-type object byassigning database columns for the display and internal values, byassigning an SQL statement to the Translation property that returns acolumn for the display and internal values, or by creating a textlist where the display value and the internal value are each listedon a separate line with an “=” sign between them, as illustratedbelow.

Aaron = A
Bobby = B
Cathy = C

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

To dynamically add entries to a list-type object, you can dynamicallyreset the Translation property of the object. In the code examplebelow, the display value, represented by the vsDisplay variable, the”=” sign and the internal value, represented by vsValue, areconcatenated onto the end of the Translation property for thelstSample list box.

DIM sNewLine As StringsNewLine = CHR(13) & CHR(10)lstSample.Translation = lstTranslation & sNewLine & &       vsDisplay & "=" & vsValue     

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

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email

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

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

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

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist