使用字符串从datagrid读取 [英] reading from a datagrid using a string

查看:59
本文介绍了使用字符串从datagrid读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我想从网格读取数据,并且返回的任何内容都由字符串存储 - 我将把它与文本框中输入的数据进行比较。当我遍历网格时,它只读取第一行并且不识别其他记录。



>这是我循环网格的代码..请帮助。



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.

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

推荐答案

尝试用行替换dgvBarcode.Rows [0],因此它实际上使用了foreach循环的迭代器。



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

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


尝试这样做但我收到错误对象引用没有设置为对象的实例。
tried doing it that way but I got an error "Object reference not set to an instance of an object."


这篇关于使用字符串从datagrid读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆