循环遍历 DataGridView 单元格 [英] Looping through DataGridView Cells

查看:56
本文介绍了循环遍历 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天全站免登陆