Selecting of 2 rows in a table programmatically

Hi,

Can someone provide me any idea on how i can select 2 rows in a table on the load of the data.

Basically, I have to select the first and second row by default.

Subsequently, when the user clicks on row 3, row 4 should be selected too.

Thanks a lot in advance.

with table.setMultiSlect(true) you turn on multi selection. With table.getItemIds() you’ll get all the items in the table. Take the two first items of what the collection contains, and put them into a set. give that set to the table with setValue(Object) to select the two rows.

… and just in case as a small clarification: the table value is an item identifier (if in single select mode) or a Set of item identifiers (if in multiselect mode), not items.

Hi,

Thanks for the reply.

I have implemented the above, but when i set the table.setMultiSelect(true)… my non-readonly fields are becoming disabled in the table…

But my first and second rows are getting highlighted…

Below is my code snippet:

public void buildPanel() {
this.removeAllComponents();

	table.setHeight(100, UNITS_PERCENTAGE);
	table.setWidth(100, UNITS_PERCENTAGE);
	
	table.setPageLength(20);
	table.setEditEnabled(true);
	table.setSelectable(true);
	table.setMultiSelect(true);
	table.setImmediate(true);
	
	addComponent(table);

	refreshTable();
	
	addComponent(saveDataButton);
}

public void refreshTable(List<Messages> msgs) {
	int msgCount = 0;
	table.deleteAllRows();
	
	for(Message msg : msgs) {
		table.addRow(msg);
	}
	HashSet set = new HashSet();
	Iterator iterator = table.getItemIds().iterator();
	
	while(iterator.hasNext()){
		msgCount++;
		set.add(iterator.next());
		if(msgCount== 2){
			break;
		}
	}
	
	for(Message row : (List<Message>)table.getNewRows())
	{
		table.setValue(set);
	}
}