mardi 20 juin 2017

When I have Check Box checked how to delete row from Table View?

I have these items:

@FXML
private Button bttnRemove;
@FXML
private TableView<EventsBean> eventsTable;
@FXML
private TableColumn<EventsBean, String> eventCol;
@FXML
private TableColumn<EventsBean, LocalDate> dateCol;
@FXML
private TableColumn<EventsBean, Boolean> doneCol;
@FXML
private TableColumn<EventsBean, String> observationCol;
@FXML
private TableColumn<EventsBean, Boolean> removeCol;

and in removeCol I create checkboxes:

ObservableList<EventsBean> dataList = FXCollections.observableArrayList();

@Override
public void initialize(URL location, ResourceBundle resources) {

      removeCol.setCellFactory(CheckBoxTableCell.forTableColumn(removeCol));
      removeCol.setCellValueFactory(new PropertyValueFactory<EventsBean, Boolean>("remove"));
      eventsTable.setItems(dataList);

      bttnAddEvent.setOnAction((ActionEvent e) -> {
        text = eventsSelector.getValue().toString();
        dataList.add(new EventsBean(text, isoDate, ""));
    });

      bttnRemove.setOnAction((ActionEvent e) -> {
        //code here...
    });
 }

I want to use bttnRemove to delete a row that have checkbox checked from removeCol.




Aucun commentaire:

Enregistrer un commentaire