0
데이터를 저장하기 전에 하나 이상의 DataGridview 셀이 null인지 아닌지를 필터링하거나 확인할 때 도움이 필요합니다. 몇 가지 코드를 시도했지만 항상 오류가 있습니다. 아래 그림이 있습니다. 사전에vb.net에서 버튼 클릭으로 DataGridview 셀이 비어 있는지 확인하는 방법은 무엇입니까?
감사합니다.
데이터를 저장하기 전에 하나 이상의 DataGridview 셀이 null인지 아닌지를 필터링하거나 확인할 때 도움이 필요합니다. 몇 가지 코드를 시도했지만 항상 오류가 있습니다. 아래 그림이 있습니다. 사전에vb.net에서 버튼 클릭으로 DataGridview 셀이 비어 있는지 확인하는 방법은 무엇입니까?
감사합니다.
For Each rw As DataGridViewRow In dataGridView1.Rows
For i As Integer = 0 To rw.Cells.Count - 1
If rw.Cells(i).Value Is Nothing OrElse rw.Cells(i).Value = DBNull.Value OrElse String.IsNullOrWhitespace(rw.Cells(i).Value.ToString()) Then
'empty
End If
Next
Next
이 같은 기능을 쓸 수 있습니다 :
Public Function IsDataGridViewEmpty(ByRef dataGridView As DataGridView) As Boolean
Dim isEmpty As Boolean = True
For Each row As DataGridViewRow In dataGridView.Rows
For Each cell As DataGridViewCell In row.Cells
If Not String.IsNullOrEmpty(cell.Value) Then
If Not String.IsNullOrEmpty(Trim(cell.Value.ToString())) Then
isEmpty = False
Exit For
End If
End If
Next
Next
Return isEmpty
End Function
또는 Linq에와 :
Public Function IsDataGridViewEmpty(ByRef dataGridView As DataGridView) As Boolean
Dim isEmpty As Boolean = True
For Each row As DataGridViewRow In From row1 As DataGridViewRow In dataGridView.Rows Where (From cell As DataGridViewCell In row1.Cells Where Not String.IsNullOrEmpty(cell.Value)).Any(Function(cell) Not String.IsNullOrEmpty(Trim(cell.Value.ToString())))
isEmpty = False
Next
Return isEmpty
End Function
을 ... 선생님 당신이 vb.net 코드 please..Thanks –
번역하시기 바랍니다 수 VB에서 번역. 도움이되기를 바랍니다. –
선생님 제안 된 코드를 사용해 보았지만 빈 셀이 있더라도 저장합니다. –