本文介绍了删除代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我更改了删除代码,但不知道出了什么问题以及为什么它停止工作.
首先,代码是为一个简单的列表框创建的,但随后决定添加复选框,但删除后发现了相同的搜索结果,并且弹出的消息框显示...文件System.windows.forms.checkedlistbox + checkeditemcollection成功删除了吗?
I have altered a delete code but have no idea what went wrong and why it has stopped working.
To start with the code was made for a simple listbox but then decided to add checklistbox but the same search results are found after deleting and the msgbox that pops up says... File System.windows.forms.checkedlistbox+checkeditemcollection successfully deleted?
Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button3.Click
red = Replace(CheckedListBox1.CheckedItems.ToString,"Threat Found:","")
Try
System.IO.File.Delete(red)
If Dir(red) <> "" Then
MsgBox("Unable to delete" & red, msgboxstyle.critical)
Else
MsgBox(String.Format("File {0} successfully deleted", red),
MsgBoxStyle.Critical)
CheckedListBox1.Items.Remove (CheckedListBox1.CheckedItems)
End If
Catch ex As Exception
End Try
End Sub
推荐答案
Dim arrList As New ArrayList()
For Each item As Object In CheckedListBox1.CheckedItems
arrList.Add(item)
Next
For Each item As Object In arrList 'iteration
red = Replace(item.ToString(), "Threat Found:","")
Try
System.IO.File.Delete(red)
If Dir(red) <> "" Then
MsgBox("Unable to delete" & red, MsgBoxStyle.Critical)
Else
MsgBox(String.Format("File {0} successfully deleted", red), MsgBoxStyle.Critical)
CheckedListBox1.Items.Remove(item)
End If
Catch ex As Exception
Console.WriteLine("{0}", ex.Message)
End Try
Next
Dim arrList As New ArrayList()
For Each item As Object In CheckedListBox1.CheckedItems
arrList.Add(item)
Next
For Each item As Object In arrList 'iteration
red = Replace(item.ToString(), "Threat Found:","")
Try
System.IO.File.Delete(red)
If Dir(red) <> "" Then
MsgBox("Unable to delete" & red, MsgBoxStyle.Critical)
Else
MsgBox(String.Format("File {0} successfully deleted", red), MsgBoxStyle.Critical)
CheckedListBox1.Items.Remove(item)
End If
Catch ex As Exception
Console.WriteLine("{0}", ex.Message)
End Try
Next
这篇关于删除代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!