devxlogo

Dependent values

Dependent values

Question:
I want to create a list box that will contain values based on the value ofanother list box. How can I accomplish this?

Answer:
A list box is populated whenever the Translation property for thelist box is set. To populate a list box based on the value of another listbox, set the Translation property of the second list box in thePostChange() method of the first list box.

If the first list box is called lstSource, and the second iscalled lstPopulate, the lstSource box contains adepartment number, lstPopulate contains the NAME and ID ofemployees of the selected department and the Datatype of the two listboxes is “String,” the code in the PostChange() method oflstSource would read:

lstPopulate.Translation = “= SELECT NAME, ID FROM EMPLOYEE WHERE DEPT = ‘” & &        lstSource.Value & “‘”

Notice that you must insert the Value of the lstSourcelist box in single quotes, since the SQL statement will need the actualvalue rather than a bind variable.

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