PDA

View Full Version : ListView multi selection - select items programmatically



msimone
13 Dec 2010, 9:07 AM
Good evening everybody,

I'd like to select programmatically several items of a multiselection listview.

Can some one please tellme how to do that?

Thanks

Best Regars

Matteo

sven
13 Dec 2010, 9:11 AM
I'd like to select programmatically several items of a multiselection listview.

Can some one please tellme how to do that?

The selectionmodel as public methods to select items, you probably want to use one of them:

listView.getSelectionModel() will return you the selectionmodel.

msimone
17 Dec 2010, 12:47 AM
Thanks for reply.

I have a custom inherited BaseModelData list and I tried to fill the list into the listView and select all them in this way:

List<ModuloModelData> listObj = new List<ModuloModelData>();

listObj = getObjects();

listView.getSelectionModel().getSelectionModel().setSelection(listObj);
listView.getSelectionModel().selectAll();

Where MOduloModelData is an objet inherited from BaseModelData and hetObjects() is a method that return a listo of ModuliModelData.

The result is a combobox filled with the values but none of them is selected.

Any suggestion, please?

Thaks

Matteo

sven
17 Dec 2010, 12:49 AM
The result is a combobox filled with the values but none of them is selected.

Any suggestion, please?

A ComboBox can only have one item, and you need to set it with setValue.

A ComboBox is not a ListView.

msimone
17 Dec 2010, 12:56 AM
Sorry Sven,

I would mean ListView not ComboBox.
The ListView I' using is defined in this way:

private ListView<ModuloModelData> listView

Thaks

sven
17 Dec 2010, 12:57 AM
Please post a fully working testcase that implements EntryPoint, demonstrates exactly what you are doing and is runnable without further depencies.

msimone
17 Dec 2010, 7:33 AM
ListStore<ModuloModelData> moduliStore = new ListStore<ModuloModelData>();


List<ModuloModelData> listModuloStore =new ArrayList<ModuloModelData>();
listModuloStore.add(new ModuloModelData(1,"SAAB","9000"));
listModuloStore.add(new ModuloModelData(1,"SAAB","9002"));
listModuloStore.add(new ModuloModelData(1,"SAAB","9003"));
moduliStore.add(listModuloStore);

List<ModuloModelData> listSubModuloStore =new ArrayList<ModuloModelData>();


listSubModuloStore.add(new ModuloModelData(3,"VW","GOLF"));
listSubModuloStore.add(new ModuloModelData(4,"Peugeot","307"));

ListViewSelectionModel<ModuloModelData> listViewSelectionModel= new ListViewSelectionModel<ModuloModelData>();
listViewSelectionModel.setSelectionMode(SelectionMode.MULTI);

//THROWS NULLPOINTER EXCEPTION
listViewSelectionModel.select(listSubModuloStore, true);


listViewSelectionModel.selectAll();


modulo = new ListView<ModuloModelData>();
modulo.setStore(moduliStore);

modulo.setSimpleTemplate("<i>{nome}</i> <b>{nota}</b>");




modulo.setSelectionModel(listViewSelectionModel);
modulo.getSelectionModel().selectAll();


What is wrong? tnx

sven
17 Dec 2010, 7:57 AM
//THROWS NULLPOINTER EXCEPTION
listViewSelectionModel.select(listSubModuloStore, true);


Its because listviewselectionmodel is not set on a ListView yet.


I just did a small testcase against GXT 2.2.1 and it works fine for me. Which version are you using?

msimone
17 Dec 2010, 8:42 AM
Hi Sven,

thankyou very much.

Solved.

I'm using 2.1.0 verison of GXT.

Now I'm goint to use the RPC proxy loader mode to take Items from the server.

Thaks

Matteo