Visual Basic,如何读取数据网格中的每一行? [英] Visual Basic, How do I read each row in a datagrid?

查看:26
本文介绍了Visual Basic,如何读取数据网格中的每一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 DataGridView1 的数据网格,A 列包含一个名称,B 列包含一个文件路径.如何为每一行运行一些代码?以这种方式遍历数据网格的正确术语是什么?

I have a datagrid called DataGridView1, column A contains a name, column B contains a path to a file. How do I run some code for each row? What is the correct terminology for traversing a datagrid in this way?

我需要的示例:

For each row in DataGridView1
 MessageBox.Show DataGridView1.ColumnA.text & "," & DataGridView1.ColumnB.text

谢谢

推荐答案

您快到了,您需要类似以下内容:

You were nearly there, you need something like the following:

For Each row As DataGridViewRow In DataGridView1.Rows
    If Not row.IsNewRow Then
        MessageBox.Show(row.Cells(0).Value.ToString & "," & row.Cells(1).Value.ToString)
    End If
Next

如果您的 DataGridView 允许添加行,您需要检查 row.IsNewRow 是否不为 True.

You need to check if the row.IsNewRow is not True if your DataGridView allows adding rows.

这篇关于Visual Basic,如何读取数据网格中的每一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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