How to remove a row from Flex Table

147 views
Skip to first unread message

vikky

unread,
Oct 11, 2011, 6:01:43 AM10/11/11
to Google Web Toolkit, verma....@tcs.com
Hi ,

I am using a Flex Table in which i want to "Add" and "Remove" the
row, Add functionality working properly but in case of Remove, when i
tried to remove more then one row from the table it thrown an
exception "IndexOutOfBound"


Please do the needful.
Regards,
Vikas verma

misko237

unread,
Oct 11, 2011, 11:42:18 AM10/11/11
to Google Web Toolkit
Hi,

just one thing to check. Row counting starts with 0. Maybe you're
trying to remove last row with wrong index (+1 error). Or trying to
remove row from empty table.

Sudhakar Abraham

unread,
Oct 12, 2011, 8:31:58 AM10/12/11
to Google Web Toolkit
First count the number of rows in FlexTable using getRowCount()
method. Remove specific row from flex table using
removeRow( int row).

Ex:

int count = myFlexTable.getRowCount();

for (int i = 0; i < count; i++)
{
myFlexTable.removeRow(i);
}

S. Abraham
www.DataStoreGwt.com
Persist objects directly in App Engine

Paul Robinson

unread,
Oct 12, 2011, 8:44:30 AM10/12/11
to google-we...@googlegroups.com
On 12/10/11 13:31, Sudhakar Abraham wrote:
> First count the number of rows in FlexTable using getRowCount()
> method. Remove specific row from flex table using
> removeRow( int row).
>
> Ex:
>
> int count = myFlexTable.getRowCount();
>
> for (int i = 0; i< count; i++)
> {
> myFlexTable.removeRow(i);
> }
>
> S. Abraham
> www.DataStoreGwt.com
> Persist objects directly in App Engine

That code won't work. You'll probably get an IndexOutOfBoundsException. The first time through the loop, you will remove row 0. What was originally row 1 will then be row 0, and what was originally row 2 will be row 1 etc. So on the second time through the loop, you remove row 1, but that is the row that was originally row 2. So the row that was originally row 1 would never be deleted. When you get far enough through removing rows, you'll get an exception.

To delete all the rows one at a time (rather than calling myFlexTable.removeAllRows()), try something like this:

int count = myFlexTable.getRowCount();

for (int i = count-1; i>=0 ; i--)
{
myFlexTable.removeRow(i);
}

or else something like this:

int count = myFlexTable.getRowCount();

for (int i = 0; i< count; i++)
{

myFlexTable.removeRow(0);
}

Paul

Reply all
Reply to author
Forward
0 new messages