Visual Basic Programming Help

1
Private Sub GridWithLoop()

    Dim sum As Integer = 0
    Dim sum2 As Integer = 0
    Dim allrow As DataGridViewRow
    Dim band As DataGridViewBand

    For i As Integer = 0 To DataGridView2.Rows.Count() - 1 Step +1
        'sum = sum + DataGridView2.Rows(i).Cells(1).Value'
        allrow = DataGridView2.Rows(i)

        If allrow.Cells(1).Value.ToString = TextBox1.Text Then
            'Nothing happen'
        Else
            band = DataGridView2.Rows(i)
            band.Visible = False
        End If
    Next
End Sub

I am not able to make it work, it gives error when I try to put row as invisible, can someone help me?

    
asked by anonymous 26.04.2016 / 00:27

1 answer

1

Does your DataGridView allow insertion of rows? You can not hide the line that is pending for new data entry. Test the allrow.IsNewRow property to avoid this. I do not understand why you are using the DataGridViewBand object for this purpose? Try this:

Private Sub GridWithLoop()

    Dim sum As Integer = 0
    Dim sum2 As Integer = 0
    Dim allrow As DataGridViewRow
    Dim band As DataGridViewBand

    For i As Integer = 0 To DataGridView2.Rows.Count() - 1 Step +1
        'sum = sum + DataGridView2.Rows(i).Cells(1).Value'
        allrow = DataGridView2.Rows(i)

        If allrow.Cells(1).Value.ToString = TextBox1.Text Then
            'Nothing happen'
        ElseIf Not allrow.IsNewRow Then
            allrow.Visible = False
        End If
    Next
End Sub    
    
25.05.2016 / 00:51