TX Text Control Blog

Removing TextFields in a loop

Blogged by Björn Meyer on March 12, 2009 and tagged with textfields, sample, .net.

A typical problem with collections is the fact that you can't remove elements of the collection in a loop.

To remove specific fields in TX Text Control, you could add the fields to another array in order to remove these fields using the TextFields.Remove method or you can use the field enumerator:

TXTextControl.TextFieldCollection.TextFieldEnumerator fieldEnum = textControl1.TextFields.GetEnumerator(); int fieldCounter = textControl1.TextFields.Count; for (int i = 0; i <= fieldCounter; i++) { fieldEnum.MoveNext(); TXTextControl.TextField curField = (TXTextControl.TextField)fieldEnum.Current; textControl1.TextFields.Remove(curField); }

This little code snippet removes all fields from the TextFieldCollection of TX Text Control. Of course, this could also be easily solved using the Clear method of the TextFieldCollection. It just should show how to use the enumerator.

 
 
 

Products

Support

Downloads

Corporate

Buy Now