Visual Basic,如何读取datagrid中的每一行? [英] Visual Basic, How do I read each row in a datagrid?
本文介绍了Visual Basic,如何读取datagrid中的每一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要的示例:
对于DataGridView1中的每一行
MessageBox.Show DataGridView1.ColumnA.text& ,& DataGridView1.ColumnB.text
谢谢
解决方案
你几乎在那里,你需要像下面这样的东西:
DataGridViewRow在DataGridView1.Rows
如果不是row.IsNewRow然后
MessageBox.Show(row.Cells(0).Value.ToString&,& row.Cells(1).Value.ToString )
结束如果
下一个
编辑:
如果您的DataGridView允许添加行,则需要检查row.IsNewRow是否为True。
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?
Example of what I need:
For each row in DataGridView1
MessageBox.Show DataGridView1.ColumnA.text & "," & DataGridView1.ColumnB.text
Thanks
解决方案
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
EDIT:
You need to check if the row.IsNewRow is not True if your DataGridView allows adding rows.
这篇关于Visual Basic,如何读取datagrid中的每一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文