Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

collection class problem.emergency help please

Dear Sirs

I have class ,say MyLines,derived from CollectionBase,and I have implemented some collection functions
like Add,Remove,Item and Find in this class.
This class is enumerable and I can use foreach statement like this
foreach(Myline l in myLines)
{
......
}

But unfortunately I foun that after removing some objects from this collection,(from its innerlist)
this class isn't enumerable anymore and I can't use foreach statement and I receive this message:

"Collection was modified;enumeration operation may not execute"

how can I fix this problem?what's wrong with this collection class?here is my code for this class:

public class Lines:System.Collections.CollectionBase
{
private DLine mDLine;
private bool Check;
public Guid[,] mLineBack;

public BLines(bool WithDataSet)
{
if (WithDataSet)
this.mDLine=new DLine();
}
public BLines(Guid KeyUser)
{
mDLine=new DLine(KeyUser);
foreach(DataRow Dr in mDLine.mDTLine.Rows)
{
this.InnerList.Add(new Line((Guid)Dr["LineID"]));
}
}
public Line Add(Line lLine)
{
if (mDLine!=null)
{
if (mDLine.Add(lLine)=="")
Check=true;
this.InnerList.Add(lLine);
return lLine;
}
return null;
}
public Line Item(int Index)
{
if(this.Count==0)
return null;

if (Index!=-1)
return (Line) this.InnerList[Index];
else
return null;
}
public Line Item(Line lLine)
{
if(this.Count==0)
return null;

int i=this.InnerList.IndexOf(lLine);
if (i!=-1)
return (Line) this.InnerList[i];
else
return null;
}
public void Remove(Line lLine)
{
if (mDLine!=null)
{
if (mDLine.Delete(lLine)=="")
this.InnerList.Remove(lLine);
}
else
this.InnerList.Remove(lLine);
}
public void Remove(int Index)
{
Line lLine=(Line)this.InnerList[Index];
if (lLine!=null)
this.Remove(lLine);
}
public int Find(Line lLine)
{
int i=this.InnerList.IndexOf(lLine);
return i;
}
}

Thanks in advance
Reza
Sign In or Register to comment.