public static final boolean setSelectedValue ( ListBox list , String value , boolean addMissingValues ) { if ( value == null ) { list . setSelectedIndex ( 0 ) ; return false ; } else { int index = findValueInListBox ( list , value ) ; if ( index >= 0 ) { list . setSelectedIndex ( index ) ; return true ; } if ( addMissingValues ) { list . addItem ( value , value ) ; // now that it's there, search again index = findValueInListBox ( list , value ) ; list . setSelectedIndex ( index ) ; return true ; } return false ; } }
Utility function to set the current value in a ListBox .