问题
I`m trying to add addValueChangeHandler function to a TextBox inside a flexTable. But when I add this code: int rowIndex = tableImages.getCellForEvent(event).getRowIndex(); I use this method to know the current row in case of a ClickEvent.
the method is not acceptable for ValueChangeEvent, so how can I know what is the row Index for the changed cell? Thank you.
回答1:
Well yes, because it needs a Cell itself, not a TextBox or event value. What you can do, is:
- Get the event Source via
event.getSource()
- Cast it to
Widget
at least (though it's safe to assume it's a textBox)Widget sourceWidget = (Widget)event.getSource();
- Get the source widget's element's parent
sourceWidget.getElement().getParent();
This way you'll acquire the actual <td>
cell your textBox nested in.
Then you can getCellFormatter of your table and find the index of the cell in a loop, comparing the <td>
element you got with the cells of your table.
Please tell me if it solved your problem
来源:https://stackoverflow.com/questions/35460647/gwt-getcellforevent-flextable