问题
What I'm trying to achieve is to match the Source doc no. of PER SAWT
to PER MAP
.
If it matches it will automatically check the CheckBox and it will set the BackColor
to Color.Yellow
.
But when I try to split the Source Doc in PER MAP
, it will only get the 2nd Value which is BS091
as per screenshot in 1st Scenario.
My code work in 2nd scenario.
1st Scenario

2nd Senario

Here is the code:
For x As Integer = 0 To Me.DataGridView4.Rows.Count - 1
Dim sdoc_sawt As String = DataGridView4.Rows(x).Cells("Source_Doc_No").Value.ToString
'Sample Value: "RR0022/BS091/BS092/BS093"
Dim sdoc_map As String = DataGridView4.Rows(x).Cells("Source_Doc_No_P").Value.ToString
Dim split_sdoc As String() = sdoc_map.Split("/")
Dim part As String
For Each part In split_sdoc
If Me.DataGridView4.Rows(x).Cells("Source_Doc_No").Value.ToString = part Then
Me.DataGridView4.Rows(x).Cells(0) = New DataGridViewCheckBoxCell With {.Value = True}
'-------Will automatically color the yellow of math Source Docu no.----------'
Me.DataGridView4.Rows(x).Cells(0).Style.BackColor = Color.Yellow
Me.DataGridView4.Rows(x).Cells("Source_Doc_No").Style.BackColor = Color.Yellow
Me.DataGridView4.Rows(x).Cells("ATC").Style.BackColor = Color.Yellow
Me.DataGridView4.Rows(x).Cells("Prepaid_Tax").Style.BackColor = Color.Yellow
Me.DataGridView4.Rows(x).Cells("Source_Doc_No_P").Style.BackColor = Color.Yellow
Me.DataGridView4.Rows(x).Cells("ATC_P").Style.BackColor = Color.Yellow
Me.DataGridView4.Rows(x).Cells("Tax_Withheld_P").Style.BackColor = Color.Yellow
'-----------------------------------End---------------------------------------'
End If
Next
Next
来源:https://stackoverflow.com/questions/53735905/matching-the-values-of-split-string-in-if-condition