循环遍历 DataGridView 单元格

编程入门 行业动态 更新时间:2024-10-26 12:29:13
本文介绍了循环遍历 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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-29 10:02:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/753657.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:遍历   单元格   DataGridView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!