Skip to main content

Populate Select List Based on Drop-Down Selection

This is a demo program on how you can populate a list box based on a selected field.

Snippet

This is a demo program on how you can populate a list box based on a selected field.  You first select the file, you will then be given a list of the character fields within the file. You select a field and in the background the script will summarize the field and get all the unique items in that field and place them in a list box so you can select one or more items.

BENOIT Mon, 03/11/2019 - 17:09

Hi Brian,
Do you know if it's possible to have a value by default to the droplistbox1 ? (and the items attached to this value into the listbox1) ?
Thanks.
Benoit

Brian Element Mon, 03/11/2019 - 18:14

Hi Benoit,

Yes it is but you must set the default before you call the dialog, you can't set a default once the dialog is open.  Here is some example code for you, you can copy it and paste it into your IDEAScript editor.  It has a dialog with a list of fruit, it sets the default to item 3 (which is actually the 4th item as arrays start at 0).


Dim listbox1$() AS STRING

Begin Dialog NewDialog 50,50,150,150,"NewDialog", .NewDialog
  DropListBox 18,15,90,11, listbox1$(), .DropListBox1
  OKButton 21,61,40,14, "OK", .OKButton1
End Dialog
Sub Main
	Dim dlg As NewDialog
	Dim button As Integer
	ReDim listbox1$(4)
	listbox1$(0) = "Apples"
	listbox1$(1) = "Oranges"
	listbox1$(2) = "Grapes"
	listbox1$(3) = "Bananas"
	listbox1$(4) = "Lemons"
	
	dlg.DropListBox1 = 3
	
	button = Dialog(dlg)
End Sub

BENOIT Tue, 03/12/2019 - 04:51

In fact, I wanted to get always the value "JOURNALCODE" in the DropListBox1 (in my example, a DropListBox is therfeore not necessary).
But the values in the listbox1 must change according to the input file.
Thank you

Brian Element Tue, 03/12/2019 - 07:22

In reply to by BENOIT

The lisbox1 is an array so what you need to do is find out which value in the array is the same as the value you want as the default.  I have modified my example above so that it will select Oranges as the default.


Sub Main
	Dim dlg As NewDialog
	Dim button As Integer
	ReDim listbox1$(4)
	listbox1$(0) = "Apples"
	listbox1$(1) = "Oranges"
	listbox1$(2) = "Grapes"
	listbox1$(3) = "Bananas"
	listbox1$(4) = "Lemons"
	
	'assume you are interested in Oranges being the default
	For i = 0 To UBound(listbox1$)
		If "Oranges" = listbox1$(i) Then
			Exit For
		End If
	Next i
	
	dlg.DropListBox1 = i
	
	button = Dialog(dlg)
End Sub