Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specified argument was out of the range of valid values.

Status
Not open for further replies.

tondarb

Programmer
Oct 8, 2003
37
US
Hi........
The error is ...System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index

My code is like this.........

ptoInfoData.InfoRow[] infoRow = GetInfoRow();
for (int i=0; i < infoRow.Length; i++)
{
if (! smInfoId.Contains(infoRow.info_id))

{
//did some coding here
HERE NEAR THIS LINE THAT ERROR IS COMMING

this.phInfo.Controls.AddAt( i , (ptoInstance));

}
}

I tried like this also
for (int i=0; i < InfoRow.Length -1; i++)

and also
for (int i=0; i <= InfoRow.Length; i++)

and also
this.phInfo.Controls.AddAt( i -1, (ptoInstance));

it is not working...
pls help me it is urgent

Thanks in advance....
 
Hi,

What is phInfo?

I think that it's the 'if' within the 'for' loop. You always increment 'i' but you don't always add to the collection.

For example if you don't add to the collection on iterations 0, 1 & 2 - on iteartion 3 you will try to insert at position 3 when it doesn't exit.

Hope this makes sense!

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 

thanks for ur response
phInfo is a PlaceHolder
inside the for loop it is like this....


ptoInfoData.InfoRow[] infoRow = GetInfoRow();
for (int i=0; i < infoRow.Length; i++)
{
if (! smInfoId.Contains(infoRow.info_id))

{
//did some coding here

Control ptoInstance = LoadControl@"~\Controls\bnInstance.ascx");

HERE NEAR THIS LINE THAT ERROR IS COMMING

this.phInfo.Controls.AddAt( i , (ptoInstance));

}
}

 
hi
As u said

"I think that it's the 'if' within the 'for' loop. You always increment 'i' but you don't always add to the collection. "

Yes I don't want to add everytime to the colletion...
and it is giving error on on 3rd iteartion...

Can u pls tell me logically what to do .....

 
I solved the problem...

Instead of 'AddAt' I used 'Add'

this.phInfo.Controls.Add(ptoInstance);

no need using 'i' in 'Add' as an argument, as it will always be added to the end of the collection.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top