Help in basic visual programming

Asked

Viewed 66 times

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 can’t make it work, it’s wrong when I try to make Row invisible, someone can help me?

  • Hello welcome to Sopt, you can add the error message that was displayed in your question ?

1 answer

1

Does your Datagridview allow the insertion of lines? You cannot hide the line that is pending for inserting new data. Property testing allrow.IsNewRow to prevent this. I don’t understand why you’re 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    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.