# [6.0] Listbox with multiple

satan87
255

Hello

in ZK 6.0, how can i display a listbox, with checkmark=true, multiple=true and all value selected by default ?

I got that but it's not working

SimpleListModel<TypeEvent> slm = new SimpleListModel<TypeEvent>( TypeEventImpl.getInstance().getTypesEvent() );

slm.setMultiple(true);
lstType.setCheckmark(true);

lstType.setModel( slm );
lstType.setItemRenderer(ter);

for(int i = 0 ; i < slm.getSize() ; i++){
lstType.getItemAtIndex(i).setSelected(true);
}


Thanks

delete retag edit

## 7 Replies

satan87
255

any idea ?

thanks

Matze2
773 7

I am not an expert in Java only approaches, but I think you need to maintain your selection state in the model, not in the UI objects - in your case Listitem.

satan87
255

make sense, any idea how to do it ?

satan87
255

Hello

I find a way to do it

slm = new SimpleListModel<TypeEvent>( TypeEventImpl.getInstance().getTypesEvent() );

slm.setMultiple(true);
for(int i = 0 ; i < slm.getSize() ; i++)



I'm not sure it's the best way, but it's working

Nico

Matze2
773 7

Just from looking at the code, there is also a setSelection(...) method in SimpleListModel().

satan87
255

slm.setSelection(TypeEventImpl.getInstance().getTypesEvent());


That is working too, but the request is made twice in db.

Matze2
773 7

I think you can use the same result for both entries (maybe even "must", if you do not have a customized "equals/hashCode" implementation).

[hide preview]