Skip to Content
avatar image
Former Member

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 13, 2006 at 01:42 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 13, 2006 at 01:45 PM

    Try this

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

    {

    grp.removeChild(i);

    }

    grp.removeChild(0);

    Regards,Anilkumar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 13, 2006 at 02:33 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 13, 2006 at 02:53 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

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

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

      Armin

  • avatar image
    Former Member
    Nov 13, 2006 at 03:45 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 17, 2007 at 08:38 AM

    Thanks All for the active participation and helping me out

    My problem was resolved using resetview() method.

    Add comment
    10|10000 characters needed characters exceeded