Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, In my form user select the customer from dropdown box. I populate the customer invoice's into gridview. Now I want to store that invoice no and invoice amount into array. How to complete this task ?

I tried this code but getting last row of gridview only
C#
for (int i = 0; i < gridView2.RowCount; i++)
            {
                invno = gridView2.GetRowCellValue(i, "InvoiceId");

                int[] invid = new int[] { Convert.ToInt32(invno) };
            }
Posted

1 solution

Here you find some informations about arrays in .NET and C#:
http://msdn.microsoft.com/en-us/library/aa288453%28v=vs.71%29.aspx[^]

I think that array is not good choice in this case. Why not to use Dictionary?
Assuming that you are storing data in gridView in fields like this: InvoiceId (Int32) and TotalAmount (Double), try to use this code:
C#
var invoices = new Dictionary<int,double>()
for (int i = 0; i < gridView2.RowCount; i++)
{
    invNo = gridView2.GetRowCellValue(i, "InvoiceId");
    invAmount = gridView2.GetRowCellValue(i, "TotalAmount");
    invoices.Add(invNumber, invAmount);
}


The you can iterate through you dictionary like this:
C#
foreach (int invoiceId in invoices.Keys)
{
    double invoiceAmount = invoices[invoiceId]
    Console.WriteLine(string.Format("Invoice: {0}, Total amount: {1}", invoiceId, invoiceAmount));
}


Hope that help you :)
 
Share this answer
 
v2
Comments
srihari1904 21-Mar-14 8:23am    
@marcin Thank you I solved.
Marcin Kozub 21-Mar-14 8:26am    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900