循环通过DataGridView单元格 [英] Looping through DataGridView Cells

查看:91
本文介绍了循环通过DataGridView单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个生成条形码然后打印运送标签的程序。

I am creating a program that generates a bar code and then prints the shipping labels.

我有一个功能,允许用户将电子表格上传到数据网格视图。其中一个列名称是跟踪号码。

I have a function that allows the user to upload a spreadsheet into the datagrid view. One of the column names is "Tracking Number".

我希望能够循环遍历具有跟踪号码的每个单元格,然后将条形码生成新的在一个名为条码的列中的单元格。

I would like to be able to loop through each cell that has a tracking number and then generate a barcode into a a new cell in a column called "barcode".

我知道有一个循环函数,但我从来没有使用过。

I understand there is a loop function for this but I have never used it before.

代码生成条形码如下,它调用两个类:

The code that generates the barcode is the following , it calls two classes:

 Image barc = Rendering.MakeBarcodeImage(txtTrack.Text, int.Parse(txtWidth.Text), true);
 pictBarcode.Image = barc;

任何帮助将不胜感激。我会很乐意回答任何其他问题。

Any Help would be much appreciated. I will happily answer any other questions.

推荐答案

要遍历每个单元格,可以使用foreach循环

To iterate through every cell, you can use foreach loops

foreach(DataGridViewRow row in yourDataGridView.Rows)
{
    foreach(DataGridViewCell cell in row.Cells)
    {
        //do operations with cell
    }
}

这篇关于循环通过DataGridView单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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