Access to textfields in grid cells?

Hey, i was create a grid with textfields in all columns of the second row.

GridLayout grid = new GridLayout(2,2);
grid.addComponent(new Label("Title 1"), 0, 0);
grid.addComponent(new Textfield(), 0, 1);
grid.addComponent(new Label("Title 1"), 1, 0);
grid.addComponent(new Textfield(), 1, 1);

so, the both textfields are in all columns of the second row.

now, i want to read all values of the textfields by some event.

can someone tell me, how can i access over the grid cell to the textfield?

for (int b=0; b<grid.getColumns(); b++) {
      Component c = grid.getComponent(b, 1);
      ... ??? ....
}

Thanks

Hi,

there’s nothing specific available for this. You could for example add your TextFields to some collection when you create them, for example like this:

List<TextField> tfList = new ArrayList<TextField>();
TextField tf = new TextField();
tfList.add(tf);
grid.addComponent(tf, 0, 1);

and then on your event, you just iterate the list and do what you need with the fields.

Do remember to clean up the list if you remove/regenerate the fields!

Another option would be to iterate the components just like in your code snippet. Then you could just check for the type:

for (int b=0; b<grid.getColumns(); b++) {
      Component c = grid.getComponent(b, 1);
      if(c instanceof TextField) {
          ((TextField)c).whatEver();
      }
}