For r_1 As Integer = 0 To Me.DataGridView1.Rows.Count - 1 'for loop
If Me.DataGridView1.Rows(r_1).Cells(1).Value = Me.DataGridView2.Rows(r_2).Cells(2).Value Then 'เงื่อนไข
Me.DataGridView1.Rows(r_1).DefaultCellStyle.BackColor = Color.Red 'เปลี่ยนสีพื้นหลัง
End If
Next
If Me.DataGridView2.Rows.Count <> 0 Then
For r_2 As Integer = 0 To Me.DataGridView2.Rows.Count - 1
For r_1 As Integer = 0 To Me.DataGridView1.Rows.Count - 1
If Me.DataGridView1.Rows(r_1).Cells(1).Value = Me.DataGridView2.Rows(r_2).Cells(2).Value Then
Me.DataGridView1.Rows(r_1).DefaultCellStyle.BackColor = Color.LightSkyBlue
End If
Next
Next
End If
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(i).Cells(2).Value Is DBNull.Value Then
DataGridView1.Rows(i).Cells(1).Style.BackColor = Color.Red
End If
Next
ตัวนี้ไม่ใช่ตัวในรูปนะครับ แต่ใช้แล้วเกิด Error
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'
For Each Row As DataGridViewRow In DataGridView1.Rows
If Row.Cells(1).Value Is DBNull.Value Then
Row.DefaultCellStyle.BackColor = Color.Red
Else
Row.DefaultCellStyle.BackColor = Color.Green
End If
Next
สอบถามคับผิดตรงไหน
Date :
2018-01-24 14:51:32
By :
timesurfer
No. 10
Guest
ไม่มีค่า NUll ครับ ลองเซ็คค่าว่างดู
Date :
2018-01-24 15:00:24
By :
OOP
No. 11
Guest
Code (VB.NET)
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells(1).Value <> String.Empty Then
Else
row.DefaultCellStyle.BackColor = Color.Red
End If
Next