Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Programmatically select rows in a grid

Claus Lüthje
6 years ago Nov 23, 2015 8:14am
Olli Tietäväinen
6 years ago Nov 23, 2015 10:03am
Claus Lüthje
6 years ago Nov 23, 2015 10:10am
Claus Lüthje
6 years ago Nov 23, 2015 10:11am
Olli Tietäväinen
6 years ago Nov 23, 2015 10:34am

I created a selection with the following code:

Grid grid = new Grid();
    Set<Report> reports = getReports(); // Report is just a Java bean
    BeanItemContainer<Report> reportContainer = new BeanItemContainer<Report>(
                Report.class, reports); 
    grid.setContainerDataSource(reportContainer);
    MultiSelectionModel msm = new MultiSelectionModel();
    grid.setSelectionModel(msm);
    Iterator<Report> iter = reports.iterator();
    // select two objects from the Set
    msm.select(iter.next(), iter.next());

and it seems to work as it should, two items in the grid are selected.

EDIT: it also works if I change the last line to the following:

Set<Report> three = new HashSet<Report>();
    three.add(iter.next());
    three.add(iter.next());
    three.add(iter.next());
    msm.select(three);
Claus Lüthje
6 years ago Nov 23, 2015 10:50am
Claus Lüthje
6 years ago Nov 23, 2015 11:32am
Claus Lüthje
6 years ago Nov 23, 2015 1:15pm
Olli Tietäväinen
6 years ago Nov 23, 2015 1:46pm
Claus Lüthje
6 years ago Nov 24, 2015 10:30am
Olli Tietäväinen
6 years ago Nov 24, 2015 10:54am
Claus Lüthje
6 years ago Nov 24, 2015 10:56am
Claus Lüthje
6 years ago Nov 24, 2015 11:30am
Claus Lüthje
6 years ago Nov 25, 2015 8:38am
Teemu Suo-Anttila
6 years ago Nov 25, 2015 9:40am
Claus Lüthje
6 years ago Nov 25, 2015 10:19am
Teemu Suo-Anttila
6 years ago Nov 25, 2015 11:18am
Claus Lüthje
6 years ago Nov 25, 2015 11:20am
Claus Lüthje
6 years ago Nov 26, 2015 10:38am
Pere Pasqual
5 years ago Dec 29, 2016 9:42am
Steve Demy
5 years ago Mar 18, 2017 8:05am
Laurent De Laprade
3 years ago Jan 18, 2019 2:51pm