How to add, select then edit a row in a Grid

I am adding a new row to a Grid by adding a BeanItem to the underlying Container as follows:

BeanItem beanItem = new BeanItem(user);
Item item = container.addBean(user);

A new row is successfully appended to the Grid.
My question is: How do I then select that new row so I can something like


My goal is to have an Add button that adds a new row to my grid, selects that row, then edits that row.

Advice much appreciated!

This depends a bit which type of container you use. It seems that you are using BeanItemContainer, in which case BeanItem itself is also the ItemId. This means that you can directly apply grid.editItem(beanItem); in your case.

Hi Tatu
Thank you for your reply, yes I am using a BeanItemContainer.
I tried the following code based on your suggestion:

User user = new User();
BeanItem beanItem = container.addItem(user);

The last line produces the following error:

Item with id false not found in current container

I wondered if the id in question was the id field of the user bean, so I saved user after creating it and confirmed it had a valid value, however I got the same error.
Any suggestions?

Problem sorted, the following code worked fine:

User user = new User(mainMenuBuilder.getDataAccess());
BeanItem beanItem = container.addItem(user);

Good that you found the solution.