如果条件中的拆分字符串未显示所有拆分值。 VB.NET

时间:2018-12-22 06:51:30

标签: vb.net

我正在将分割的Source_Doc_No_P的PER MAP与PER SAWT进行比较,如果匹配,它将把DataGridview的BackColor着色为黄色,但是当分割Source_Doc_No_P的值时我的代码有问题在If条件内,它仅获得1个分割字符串的值。请查看屏幕截图和代码,以帮助您了解我的问题。

For x As Integer = 0 To Me.DataGridView4.Rows.Count - 1

    Dim sdoc_map As String = DataGridView4.Rows(x).Cells("Source_Doc_No_P").Value.ToString

    Dim split_sdoc() As String = sdoc_map.Split("/")

    For Each part As String In split_sdoc
        'Output of split_doc after For each loop
        'BS091
        'BS092
        'BS093
         If part = Me.DataGridView4.Rows(x).Cells("Source_Doc_No").Value.ToString Then
             'Output of split_doc after If condition
             'BS091
             'It should be
             'BS091
             'BS092
             'BS093A

             '-------Will automatically color the yellow of mathced Source Document----------'
             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 = 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

当前结果 img1

应该是什么结果 img2

1 个答案:

答案 0 :(得分:0)

    Dim sdoc_map As String = DataGridView4.Rows(x).Cells("Source_Doc_No_P").Value.ToString 

在这里检查。我认为只是与单元名称混淆了。因为此处不存在Cells(“ Source_Doc_No_P”)。检查单元格名称,然后继续。