Hi, I have some value at column named "data".

I need to scan the value at that column, if more than "2", then column named "1" will be "1 = data -2"

Then at next row and still in current column named "data" , if more than "2", then column named "1" will be "1 = data ".

Because I just want the operation done in once.

The problem is, how to make the operation done in once ? the code below show it scan all the row

The picture below show the data I highlighted.
Picture 1

The picture below show the error.
Picture 2

Here the code :


            For x As Integer = 0 To DataGridView1.Rows.Count - 1

                'Strategy 1
                If Val(DataGridView1.Rows(x).Cells(7).Value) <= 2 Then

                    DataGridView1.Rows(x).Cells(7 + 1).Value = DataGridView1.Rows(x).Cells(7).Value - 2

                    DataGridView1.Rows(x).Cells(7 + 1).Value = DataGridView1.Rows(x).Cells(7).Value
                End If


        Catch ex As Exception

        End Try
Attachments high.PNG 46.78 KB error.PNG 45.33 KB
3 Years
Discussion Span
Last Post by Mr.M

Hi, I figured out that I should break the statement if some condition is meet..

How to break this statement, if this condition is meet ?

Val(DataGridView1.Rows(x).Cells(7).Value) <= 2 

then after the above statement is meet, it should continue with this statement

DataGridView1.Rows(x).Cells(7 + 1).Value = DataGridView1.Rows(x).Cells(7).Value

Here is how to check if the condition is met or not.

 If Val (DataGridView1.Rows(x).Cells(7).Value) <= 2 Then
 ' Here the condition is met
 ' You can put your code you want to process while this condition is met
 ' The condition is not met
 End If
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.