Hi all expert,
I have two fields in data grid one comboxbox type another is texbox type. As per user selection I want to add multiple record at a time in backend. Here is my looping code…pls somebody help………help…help………me..inside looping code I am getting casting exceptions.
Unable to cast object of type 'System.String' to type 'Create_Sales_Back_Order.DynamicsGPService.SalesBackorderLine[]'.
for (int counter = 0; counter < (CreateSalesBackOrderGrid.Rows.Count); counter++)
{
salesBackorder.Lines = (SalesBackorderLine[])CreateSalesBackOrderGrid.Rows[counter].Cells[0].Value; //here getting this exception.
//here I should write insert method.
}

Manikavelu VelayuthamRank #413 · 6K reputationPosted Sep 27, 2010, 1:06 AM EDT
May i know what type is it
India Programmer43 reputationPosted Sep 27, 2010, 4:14 AM EDT
Hi,
Now I have changed the code: getting exception.. Index out of range.
SalesBackorderLine[] lines = new SalesBackorderLine[CreateSalesBackOrderGrid.Rows.Count];
for (int counter = 0; counter < CreateSalesBackOrderGrid.Rows.Count; counter++)
{
salesBackorderLine = new SalesBackorderLine();
salesBackorderLine.ItemKey = itemKey;
salesBackorderLine.Quantity = backorderCount;
lines[CreateSalesBackOrderGrid.Rows.Count]=salesBackorderLine; //in this line getting exception Index out of range.
}
Manikavelu VelayuthamRank #413 · 6K reputationPosted Sep 27, 2010, 4:16 AM EDT
for (int counter = 0; counter < CreateSalesBackOrderGrid.Rows.Count; counter++)
with this code
for (int counter = 0; counter < CreateSalesBackOrderGrid.Rows.Count-1; counter++)
India Programmer43 reputationPosted Sep 27, 2010, 4:22 AM EDT
Still getting the same exception "Index was outside the bounds of the array"
Manikavelu VelayuthamRank #413 · 6K reputationPosted Sep 27, 2010, 4:27 AM EDT
CreateSalesBackOrderGrid.Rows.Count and lines
If both are same then ther wont be a chance of index out of range error.
if both are not same surely it will throw the error
put a break point and debug each loop, there you can easily fix the bug
let me know once your resolved this issue
India Programmer43 reputationPosted Sep 27, 2010, 4:42 AM EDT
1)First of all though I am entering 3 records…its showing row count as 4.
2) SalesBackorderLine[] lines = new SalesBackorderLine[CreateSalesBackOrderGrid.Rows.Count];
In this lines =null showing..
and new SalesBackorderLine[CreateSalesBackOrderGrid.Rows.Count]=4 showing.
3) Lines(CreateSalesBackOrderGrid.Rows.Count) = salesBackorderLine ..here value showing as 4
Sam HobbsRank #107 · 20.5K reputationPosted Sep 27, 2010, 2:28 PM EDT