PDA

View Full Version : Refreshing a Combobox ListView



nac
28 Jul 2010, 8:08 AM
Hy all,
I'm using a combobox with a custom DisplayField.
I want my widget to change this DisplayField dynamically.
But if I do so, the ListView of the Combobox isn't updated.

for example :


public class MyWidget extends FieldSet {
private ComboBox<EmployeeModelData> cbb = new ComboBox<EmployeeModelData>();
private ListStore<EmployeeModelData> lStore = new ListStore<EmployeeModelData>();

private RadioGroup typeCbb = new RadioGroup();

public MyWidget(){
super();
lStore.add(new Employee("John","Doe"));
cbb.setDisplayField("name");
cbb.setStore(lStore);
this.add(cbb);

// the radio group that allow me to dynamically change the combobox DisplayField
Radio cName = new Radio();
cName.setId("name");
cName.setValue(true);
typeCbb.add(cName);
Radio cNick = new Radio();
cNick.setId("nick");
typeCbb.add(cNick);

this.add(typeCbb);

bind();
}

private bind(){
typeCbb.addListener(Events.Change, new Listener<BaseEvent>(){
public void handleEvent(BaseEvent be) {
switch(typeCbb.getValue().getId()){
case "nick" :
cbb.clearSelections();
cbb.setDisplayField("nick");
cbb.getListView().refresh();
break;
case "name" :
cbb.clearSelections();
cbb.setDisplayField("name");
cbb.getListView().refresh();
}
}

}



With this example, the listView isn't updated correctly (it's still a listView of the name's values), BUT, when I select one name, the selected value appear to be a nickname.
Is it a bug ?

sven
28 Jul 2010, 8:11 AM
No its not a bug.

The easiest for you would be to use two comboboxes and hide/show the needed one.

nac
28 Jul 2010, 8:19 AM
Is there any hardest way ?
Cause in the real life I need at least 5 differents comboboxes to feet my modelData. So it means a lot of memory for one widget with just one store, isn't it ?

sven
28 Jul 2010, 8:25 AM
You can also set a new Template on the ListView after changing the displayProperty which reflects the new displayProperty.

nac
29 Jul 2010, 12:10 AM
Sweet.
Definitely the best solution for my concern.
Thank's for your responses !