cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in using removechild(int index) method to remove elements

Former Member
0 Kudos

Hi All

I am using the method removechild(int index) to remove textviews from a table container.

Please let me know how should i calculate the index of elements?

Does the index starts with 0 and increments by 1 as the UIElements are added to the container ?

I started a loop and removing the elements

for ( int iCtr = 0 ; iCtr < 8 ; iCtr += 1){

tblContainer.removeChild(iCtr);

}

This code is removing the elements randomly .

Pls help

Regards

Sonal Mangla

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Yes the index starts with 0.

It is wise to start at at 8 (or wdContext.nodeName.size()) and iterate down to 0.

e.g.

for (int i=8; i>=0; i--) {

}

Good luck, Roelof

Answers (5)

Answers (5)

Former Member
0 Kudos

Thanks All for the active participation and helping me out

My problem was resolved using resetview() method.

Former Member
0 Kudos

What do you mean with "table container"? From the used method "removeChild" I guess tblContainer is some IWDUIElementContainer.

Indices always start at 0, when removing elements using iteration by index, you should iterate from end to start. If the is an iterator with deletion, use that.

To remove children from their container, you have several possibilities:

IWDUIElement[] children = container.getChildren();
container.removeAllChildren();
/* children still alive but not any longer inside container */

container.destroyAllChildren();
/* children removed from container and destroyed */

int begin = ...;
int end = ...;
for (int index = end-1; indexx >= start; --indexx)
{
  container.removeChild(index);
}
/* removes children between begin and (not including) end from the container */

Armin

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Sonal

You need to downsize index to remove all the children.


for ( int iCtr = tblContainer.numberOfChildren() ; iCtrl>=0 ; iCtr--) {
tblContainer.removeChild(iCtr);
}

or just

tblContainer.destroyAllChildren();

BR

Sergei

Message was edited by:

Siarhei Pisarenka

Former Member
0 Kudos

This loop should start at tblContainer.numberOfChildren() <b>- 1</b>.

Also note that destroy is different from remove, see Javadoc.

Armin

Former Member
0 Kudos

Hi,

if (firstTime) {

IWDTable table = (IWDTable) view.getElement("ShoppingBasket");

for(int i=0;i<table.numberOfColumns();i++)

{

table.removeColumn(i);

}

this helps for removing the columns from the table.

Thanks

Lohi.

Former Member
0 Kudos

Try this

for(int i=0;i<tblContainer.numberOfChildren();i++)

{

grp.removeChild(i);

}

grp.removeChild(0);

Regards,Anilkumar