Click here to Skip to main content
16,013,082 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys, I want to read data from a grid,and whatever's returned be stored by the string-where i will compare it with data inputted in a textbox. When I loop through the grid,it only reads the first row and doesnt recognize the rest of the other records.

>here is my code to loop through the grid..Please help.

C#
string barcode = "";
            foreach (DataGridViewRow row in dgvBarcode.Rows)
            {
                barcode = dgvBarcode.Rows[0].Cells["Equipment Barcode"].Value.ToString();
            }
Posted

Try replacing dgvBarcode.Rows[0] with row so it actually uses your iterator of the foreach loop.

C#
string barcode = "";
            foreach (DataGridViewRow row in dgvBarcode.Rows)
            {
                barcode = row .Cells["Equipment Barcode"].Value.ToString();
            }
 
Share this answer
 
tried doing it that way but I got an error "Object reference not set to an instance of an object."
 
Share this answer
 

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