cancel
Showing results for 
Search instead for 
Did you mean: 

Remove Element does not work

Former Member
0 Kudos

Hi Experts,

I want to loop over a node and remove all elements in this node if they don't match a certain pattern (which needs to be checked by getting the details o these elements).

So looping over the node and checking whether the pattern matches works pretty fine (I've checked by using a counter variable which counts the number of matches and compares to the total size of the node). But removing the elements does not work.

I always get the complete table as the result but not without all those elements I that they'd be removed already. I also check the success status (boolean) of the remove function and it delivers always "true" so it seems to work.

This is the relevant coding:

	  for(int c = 0 ; c < wdContext.nodeMatnrlist().size() ; c++){
		wdContext.nodeMatnrlist().moveTo(c);		
		GetMaterialDetails(wdContext.currentMatnrlistElement().getMaterial());		
		
		if(!wdContext.currentMaterialDetailsElement().modelObject()
.getOutput().getMaterial_General_Data().getCreated_By().equals("BAIV-SS09-21")){
			success = wdContext.nodeMatnrlist().removeElement(wdContext.nodeMatnrlist().getCurrentElement());
			counter++;
		}
	  }

any Ideas on this?

Many thanks in advance!

Cheers

Tobias

Edited by: Tobias Fickinger on Sep 4, 2009 7:04 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Loop backwards to avoid index troubles:


IWDNode node = ...;
for (int i = node.size() - 1; i >= 0; --i)
{
  IWDNodeElement e = node.getElementAt(i);
  if ( condition(e) )
    node.removeElement(e); 
}

Armin

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

If u want to remove the row at position "i" in a table, then use this piece of code:

wdcontext.nodeVn_Table.removeElement( wdcontext.nodeVn_Table.getVn_TableElemenyAt(i)));

Regards,

Himanshu

Former Member
0 Kudos

Hi Tobias.

Try this instead:


wdContext.nodeMatnrlist().invalidate();

Regards.

Julio Herrera