Ulkurz
Ulkurz

Reputation: 83

How to get the table row index based on value in a particular column

Fairly simple question: I want to get the row index of the table based on value in a particular column. Lets say the column name is "ID", it has unique values in my TableView.

Now, I want to retrieve the row index where the column "ID" is 22.

I only have access to the TableView object and the column("ID") value with me.

Upvotes: 0

Views: 3397

Answers (2)

Tutorials To Learn
Tutorials To Learn

Reputation: 1

If you want to select row using mouse. Than you can try something like this

tableview.getSelectionModel().getSelectedItem()

Upvotes: -1

Keyur Bhanderi
Keyur Bhanderi

Reputation: 1544

Use this code.

   for (int i = 0; i < tableView.getItems().size(); i++) {
        if (tableView.getItems().get(i).getId() == 22) {
            System.out.println("Selected Index : "+i);
        }
    }

Upvotes: 2

Related Questions