2010-06-27 8 views
0

누군가가이 문제를 해결할 수 있습니까?레이블의 텍스트가 DataGridview에 있는지 확인

레이블의 텍스트를 DataGridview에 추가하고 있습니다. 하지만 삽입하기 전에 텍스트가 이미 datagridview에 있는지 확인하고 싶습니다. 나는 겹쳐있다. 도움이 필요하다.

미리 감사드립니다.

답변

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 
관련 문제