In MS Access a 'ListBox' can hide the first 'column' of a 2 column ResultSet - it's great for hiding 'IDs' which are easily accessible when the user selects an item from the list.
If possible I want to do the same in JavaFX with a ListView so I can populate a second ListView based on the selection from the first ListView.
This is how I populate the ListView :
menuList1.setItems(MenuUtilities.getDivisions());
from
public static ObservableList getDivisions() {
ObservableList divisionListRow = FXCollections.observableArrayList();
try {
Connection conn;
conn = Connect_db.getConnection();
String query = "SELECT ID, Division FROM tbl_ref_employee_divisions";
PreparedStatement prestate = conn.prepareStatement(query);
ResultSet divsResult = prestate.executeQuery();
while (divsResult.next()) {
for (int i = 1; i <= divsResult.getMetaData().getColumnCount(); i++) {
divisionListRow.add(divsResult.getString(i));
}
}
prestate.close();
divsResult.close();
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return divisionListRow;
}
the listview displays : see image of List View Output
From the image I get the impression a listView cannot format an array. If so, am I better using a single column TableView? And if so how do I display one string column from the ObservableList and access the integer ID of the selected item in code.
many thanks