View Full Version : XComboBox and CheckBoxListView
blay
14 Mar 2011, 11:25 AM
Hello:
I´ve been searching threads about this issue and I´ve found some posts where it´s said that he issue about not being able to make selections from XcomboBox (via setSelection) is due to CheckBoxListView. I´m using GXT 2.2.1 and it still doesn´t work. Any help?
Thanks
After trying for a while I´ve found a workaround for this issue. Not elegant at all, but it works (at least in my tests ;) ). Probably I´m doing something wrong but here is my temporal solution:
We add a method in "XComboBox", in order to being able to execute a protected method of ComboBox.
public void triggerBlur() {
super.triggerBlur(null);
}
We create a method where the values are set:
public void doIt(){
DeferredCommand.addCommand(new Command()
{
@Override
public void execute()
{
combo.focus();
combo.expand();
combo.setSelection(combo.getStore().getModels());
combo.triggerBlur();
}
});
The deferred command is necessary because of triggerBlur (which its invoked to lose the focus on the grid). The 'trick' is expand the combo, so now, it´s rendered and the CheckBoxListView sets right the values.
Just another tip I´ve realized:
As implemented, ModelData passed to setSelection must be in the store of the comboBox. So in a case like you get values for your comboBox, and then you wanna set some of those values because an object has them (for example, a form where you wanna modify an existing object), it´s necessary to find the model in the store (because to set it true it HAS to be the same object).
A method for doing that would be:
public void setSelection(List<D> selection, String key) {
ListStore<D> tempStore = getStore();
for (D d : selection) {
((CheckBoxListView<D>) getView()).setChecked(
tempStore.findModel(key, d.get(key)), true);
}
super.setSelection(selection);
}
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.