Tom
Tom

Reputation: 845

How to get row number of a widget inside a flextable?

I found this code on internet but not sure it is the optimum solution

public int getWidgetRow(Widget widget, FlexTable table) {

        for (int row = 0; row < table.getRowCount(); row++) {
          for (int col = 0; col < table.getCellCount(row); col++) {
            Widget w = table.getWidget(row, col);
            if (w == widget) {
              return row;
            }
          }
        }

        return -1;
  }

Why FlexTable does not have a function to get a row no of a widget inside it?

Any other better solution ?

Upvotes: 2

Views: 3274

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 121998

This is the simple way:

        table.addClickHandler(new ClickHandler() { 
            @Override 
            public void onClick(ClickEvent event) {  
                 int rowIndex = table.getCellForEvent(event).getRowIndex();
            } 
        });  

Upvotes: 3

Related Questions