Subscribe Bookmark RSS Feed

Refreshing the values in a ListBox

JSL gurus,

Is there a way to refresh the values of a ListBox? Or perhaps clear all of the current values so that I can append new values? Below is a simple example where my initial list is unsorted but if the button is clicked, the values will appear in sorted order.




Thanks,
Wayne

Sorry for the formatting, first time posting.
4 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

It's a bit tedious, but apparently the only way is to select all the values in the listbox, delete them, and then add your new values in. Here's a fragment of code that may help.






style="font-size: 10pt; font-family: "Courier New"; color: green;">/*
Thanks to Don McCormack for
this. 
Dynamically changes the
caselist
listbox

style="font-size: 10pt; font-family: "Courier New"; color: black;">


 
style="font-size: 10pt; font-family: "Courier New"; color: green;">*/



style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">                       
nCases

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">N
Items

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">caselist_disp_box

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><<

style="font-size: 10pt; font-family: "Courier New"; color: black;">
Get Items)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: green;">/*
Mark all items in the listbox
as selected

style="font-size: 10pt; font-family: "Courier New"; color: black;">


 
style="font-size: 10pt; font-family: "Courier New"; color: green;">*/



style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">                       

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">For

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: teal;">1

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
i

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><=

style="font-size: 10pt; font-family: "Courier New"; color: black;">
nCases

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">++,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">                             
caselist_disp_box

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><<

style="font-size: 10pt; font-family: "Courier New"; color: black;">
Set Selected(i)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">                       
)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: green;">/*
Remove all the selected items

style="font-size: 10pt; font-family: "Courier New"; color: black;">


 
style="font-size: 10pt; font-family: "Courier New"; color: green;">*/



style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">                       
caselist_disp_box

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><<

style="font-size: 10pt; font-family: "Courier New"; color: black;">
Remove Selected

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: green;">/*
Add the resorted list back
into the listbox

style="font-size: 10pt; font-family: "Courier New"; color: black;">


 
style="font-size: 10pt; font-family: "Courier New"; color: green;">*/



style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">                       

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">For

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: teal;">1

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
i

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><=

style="font-size: 10pt; font-family: "Courier New"; color: black;">

style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 221);">N
Items

style="font-size: 10pt; font-family: "Courier New"; color: black;">(

style="font-size: 10pt; font-family: "Courier New"; color: black;">caselist_list)

style="font-size: 10pt; font-family: "Courier New"; color: navy;">,

style="font-size: 10pt; font-family: "Courier New"; color: black;">
i

style="font-size: 10pt; font-family: "Courier New"; color: navy;">++,

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; font-family: "Courier New"; color: black;">
style="">                             
caselist_disp_box

style="font-size: 10pt; font-family: "Courier New"; color: navy;"><<

style="font-size: 10pt; font-family: "Courier New"; color: black;">
Append(caselist_list[i])

style="font-size: 10pt; font-family: "Courier New"; color: navy;">;

style="font-size: 10pt; font-family: "Courier New"; color: black;">





style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: black;">
style="">                             
)

style="font-size: 10pt; line-height: 115%; font-family: "Courier New"; color: navy;">;






Regards,
Peter
That worked like a charm, Peter. Thanks for your assistance.
djhanson

Community Trekker

Joined:

Jun 23, 2011

This is sort of what I think I need to make a conditional listbox. But it doesn't quite work. The problem is that when I try to select an item it doesn't allow me to (only flashes the selected element gray in the listbox. Any ideas of what might allow me to select an item after implementing this code?
djhanson

Community Trekker

Joined:

Jun 23, 2011

Stupid me! I had placed the code in my ListBox2 :). The code worked perfectly when placed in ListBox1 (my first listbox). In my case ListBox2 depends on ListBox1 entry. It works great!