在if条件下匹配Split字符串的值

时间:2018-12-12 04:05:10

标签: vb.net datagridview

我要实现的目标是匹配源文档号。从PER SAWT到P ER MAP
如果匹配,它将自动选中CheckBox,并将BackColor设置为Color.Yellow

但是,当我尝试在PER MAP中拆分Source Doc时,根据第一个方案中的屏幕截图,它将仅获得第二个值BS091

我的代码在第二种情况下工作。

第一种情况 enter image description here

第二届塞纳里奥 enter image description here

代码如下:

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

0 个答案:

没有答案