删除包含字符串的行

时间:2015-09-02 15:25:17

标签: vb.net datagridview remove-if

我想知道如何删除这些让它们变绿的行

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    'test
    Dim examplea As String = "PAID"
    If DataGridView1.Rows.Count > 0 Then
        For i = 0 To DataGridView1.Rows.Count - 1
            If examplea = DataGridView1.Rows(i).Cells("PROJECT").Value.ToString Then
                ' MessageBox.Show("record already exist")
                DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.green
                'DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
            Else
                ''MsgBox("N-E")
                'Exit For
            End If
        Next
    End If
    'test
End Sub

1 个答案:

答案 0 :(得分:0)

我不确定我完全理解你需要什么,除非你想删除一行...

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    'test
    Dim examplea As String = "PAID"
    If DataGridView1.Rows.Count > 0 Then
       For i = DataGridView1.Rows.Count - 1 To 0 Step -1
            If examplea = DataGridView1.Rows(i).Cells("PROJECT").Value.ToString Then
                ' MessageBox.Show("record already exist")
                'DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.green
                DataGridView1.Rows.RemoveAt(i)
            Else
                ''MsgBox("N-E")
                'Exit For
            End If
        Next
    End If
    'test
End Sub