2010-06-27 94 views

回答

0

你可以只通過DataGridView的行和細胞循環和比較字符串,是這樣的:

Private Sub AddLabelToDGV(ByVal dgv As DataGridView, ByVal labelText As String) 
    Dim found As Boolean = False 
    For Each row As DataGridViewRow In dgv.Rows 
     For Each cell As DataGridViewCell In row.Cells 
      If cell.Value IsNot Nothing AndAlso cell.Value.ToString().Equals(labelText) Then 
       found = True ' if this is found it might be worth exiting the loop now instead of continuing 
      End If 
     Next 
    Next 
    If Not found Then 
     Dim row As New DataGridViewRow 
     row.CreateCells(dgv) 
     row.Cells(0).Value = labelText 
     dgv.Rows.Add(row) 
    End If 
End Sub 
相關問題