PDA

View Full Version : Removing row of a table.



Niamita
28th September 2011, 10:08
I am removing row from a table but all row of table are not delete.
I am using this code


for(int i=0; i<table.rowCount(); i++)
table->removeRow(i);

Actually i want to delete all the rows of table. What is the way to do it.

Guess I'm doing something wrong.
Any help is appreciated,

nix
28th September 2011, 11:06
Try


for(int i=table.rowCount()-1; i>=0; i--)
table->removeRow(i);

wysota
28th September 2011, 11:38
Or
table->clear();

tomkonikkara
24th November 2011, 04:17
what nix said may be correct because each deleting of a row, all other row indexes are affected.

d_stranz
26th November 2011, 01:34
If you want to remove each row, one at a time (instead of calling clear()), you could do this:



while ( table->rowCount() > 0 )
table->removeRow( 0 );


Row 0 will always be a valid index as long as the table is not empty. Using a for() loop with rowCount() as a stopping condition will always get you in trouble because both the count and the for loop index are changing as you go through the loop.