I am using DataGridView in vb.net. I would like to loop through a column and when a certain condition is met go to the next cell down and copy that into a cell in another column. So if I had 9, 1, 7, 66, 7, 9
in my first column, my second column would catch 66
and 9
the numbers that come after the specified 7
. I have managed this in vba, but can't crack it in vb.net's datagrid. Any help appreciated.
Not sure if this is what you're looking for
Before
Column1 | Column2
-------------------
9 |
1 |
7 |
66 |
7 |
9 |
After
Column1 | Column2
-------------------
9 |
1 |
7 |
66 | 66
7 |
9 | 9
Code
For i = 0 To DataGridView1.RowCount() - 1
'Check condition
If DataGridView1.Rows(i).Cells("Column1").Value = 7 Then
DataGridView1.Rows(i + 1).Cells("Column2").Value = DataGridView1.Rows(i + 1).Cells("Column1").Value
End If
Next
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.