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 :

 Try

            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

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


            Next


        Catch ex As Exception

        End Try

Recommended Answers

All 2 Replies

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
 Else
 ' The condition is not met
 End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.