hi everybody.
After a long search in the forum and after trying many methods to remove the selected item from the grid i failed.
this grid is using the VehicleGroupInfo BaseModelData.
how can i remove the selected item?
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
CheckColumnConfig checkColumn = new CheckColumnConfig("state", " ", 55);
CheckBox c = new CheckBox();
CellEditor checkBoxEditor = new CellEditor(c);
checkColumn.setEditor(checkBoxEditor);
configs.add(checkColumn);
ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader(myMessages.Groups());
column.setWidth(220);
TextField<String> text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);
final ListStore<VehicleGroupInfo> store = new ListStore<VehicleGroupInfo>();
store.add(TestData.getvehGroupModel());
ColumnModel cm = new ColumnModel(configs);
final EditorGrid<VehicleGroupInfo> grid = new EditorGrid<VehicleGroupInfo> (store, cm);
grid.setAutoExpandColumn("name");
grid.setBorders(true);
grid.addPlugin(checkColumn);
grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
window.add(grid);
/* window.addButton(new Button("Reset", new
SelectionListener<ButtonEvent>() {
@Override public void componentSelected(ButtonEvent ce) {
store.rejectChanges(); } }));*/
window.add(grid);
window.addButton(new Button(myMessages.Create(),
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
VehicleGroupInfo v = new VehicleGroupInfo();
v.setName("type here");
v.setState(false);
grid.stopEditing();
//add the new item at the end
store.insert(v, store.getCount());
grid.startEditing(0, 0);
}
}));
// removes the selected row
window.addButton(new Button(myMessages.Remove(),
new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce)
//code needed
This forum needs your help: you got hints from the community and now you have fixed your code? dont just reply with "now its fixed" or "i found the error"! please take the time to post also an detailed answer with the working code.
hi Arno
first thanks for your reply and your links.
i took my time to search well for the delete issue but i have the same problem all the time
grid.getSelectionModel().getSelectedItem(); is always pointing to null.
don't know what to do.
salam!!!!!!! hi
youpiiiiiiiiiiiiii.arno it is working now
i used your second link and it is working successfully but i had to remove the CheckColumn and change the selectionModel.
here the changes to make the code above work :
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
/*checkColumn removed*/
ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader(myMessages.Groups());
column.setWidth(220);
TextField<String> text = new TextField<String>();
text.setAllowBlank(false);
column.setEditor(new CellEditor(text));
configs.add(column);
final ListStore<VehicleGroupInfo> store = new ListStore<VehicleGroupInfo>();
store.add(TestData.getvehGroupModel());
ColumnModel cm = new ColumnModel(configs);
final EditorGrid<VehicleGroupInfo> grid = new EditorGrid<VehicleGroupInfo>(store, cm);
grid.setAutoExpandColumn("name");
grid.setBorders(true);
grid.setSelectionModel(new GridSelectionModel<VehicleGroupInfo>());
window.add(grid);
window.addButton(new Button(myMessages.Create(),
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
VehicleGroupInfo v = new VehicleGroupInfo();
v.setName(myMessages.typehere());
v.setState(false);
grid.stopEditing();
//add the new item at the end
store.insert(v, store.getCount());
grid.startEditing(store.getCount(), 0);
}
}));
// removes the selected row
Button remove=new Button (myMessages.Remove());
remove.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
grid.stopEditing();
currentlySelectedVehicle = grid.getSelectionModel().getSelectedItems();
Iterator it = currentlySelectedVehicle.iterator();
while(it.hasNext())
{
VehicleGroupInfo o =(VehicleGroupInfo) it.next();
System.out.print( " Selected groups "+ o.toString());
System.out.print(" object deleted is : "+ o.toString());
grid.getStore().remove(o);
}
if (grid.getStore().getCount() == 0) {
ce.<Component> getComponent().disable();
}
}
});
window.addButton (remove);
hope this post will be helpful to many people.
Thanx again arno.
This forum needs your help: you got hints from the community and now you have fixed your code? dont just reply with "now its fixed" or "i found the error"! please take the time to post also an detailed answer with the working code.