Reputation: 125
I have created a Grid using com.google.gwt.user.client.ui.Grid; :
Grid g = new Grid (5,5);
I have added several elements to the grid through a sql query:
g.setWidget(i, 0, texto(i, temp.get(1)));
g.setWidget(i, 1, desplegable(temp.get(2)));
g.setWidget(i, 2, texto(i, temp.get(3)));
g.setWidget(i, 3, texto(i, temp.get(4).replace("%%", "")));
g.setWidget(i, 4, gu);
"texto" and "desplegable" are both methods i have created to customize both a Textbox and a ListBox; both have a click event through which they can have their initial value changed / modified.
"gu" its a Button that i have created above the code above. "gu" has a click event which what it pretends to do is to get the values of the cell elements contained within the grid.
The following its an example:
ItemId ItemName
-----------------------
01 Peak [gu]
02 Paper [gu]
03 Pick [gu]
Now, when i click "gu", depending on which "gu" i click, i want to retrieve both values (itemid and itemname) from the grid. I know how to differenciate between which "gu" was clicked, but i dont know how to access the elements aligned to that "gu" button.
But until now i havent found how to do this.
Can anyone throw me some light on this?.
Thank you in advance for your time,
Kind regards,
Upvotes: 0
Views: 830
Reputation: 22441
You could keep a reference to the row index of each button using a map, e.g.:
Map<Button, Integer> buttonRowMap = new HashMap<Button, Integer>();
...
g.setWidget(i, 4, gu); // Your existing line
buttonRowMap.put(gu, i); // Keep a reference to the row index
Then in your ClickHandler you can retrieve the row index and the widgets on the same row:
public void onClick(ClickEvent event) {
Button button = (Button) event.getSource();
Integer rowIndex = buttonRowMap.get(button);
TextBox tb = (TextBox) g.getWiget(rowIndex, 2);
...
}
Upvotes: 1