且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何删除列表视图中的项目?网络

更新时间:2022-12-26 20:07:15

尝试检查 y 的值是否

Dim y As Integer
Dim a As String
y = ListView2.Items.Count - 1 'Reduce 1
If y < 0 Then return 'If no item then terminate
While y >= 0
    a = ListView2.Items.Item(y).Text
    'y = y - 1    'Moved to last line before End While
    Dim TMP_SQL_VAL As String = "select count([Check-Out]) from tbl_list1 where barcode = '" + a + "'"
    locconn.Open()
    command = New SqlCommand(TMP_SQL_VAL, locconn)
    Dim READER As SqlDataReader
    READER = command.ExecuteReader()
    READER.Read()

    If READER(0) = 0 Then
        MsgBox("Barcode: " & a & "is still Inside", MsgBoxStyle.Exclamation)
        clear_text()

        ListView2.Items.Remove(y)
    Else
        READER.Close()
        Dim READER2 As SqlDataReader
        Dim TMP_SQL_VAL2 = "select [Check-In] from tbl_list1 where barcode = '" + a + "' and  [User] = '" + rsuser + "'"
        Dim cmd = New SqlCommand(TMP_SQL_VAL2, locconn)
        READER2 = cmd.ExecuteReader
        READER2.Read()
        If READER2(0) Is Nothing Then
            MsgBox("Barcode: " & a & "is still Inside", MsgBoxStyle.Exclamation)
            clear_text()
        ListView2.Items.Remove(y)
        End If
   end if
   locconn.Close()

   y -= 1  'Move here so the value is decremented before the While statement

End While

Catch ex As Exception
    MsgBox(ex.Message)
    localconn.ShowDialog()
Finally
    locconn.Close()
End Try