I have two problems with my code for a CheckedListBox. I have a sub that checks to see if an item in a CheckedListBox is checked. If it is it's supposed to copy the corrisponding file to a folder. See code below.
Problem #1
I get an IndexOutOfRangeException error at line:
clbText = CheckedListBox1.CheckedItems.Item(i)
Problem # 2
After the file is copied I want the checked item to become unchecked.
Here's my code. Thanks.
Problem #1
I get an IndexOutOfRangeException error at line:
clbText = CheckedListBox1.CheckedItems.Item(i)
Problem # 2
After the file is copied I want the checked item to become unchecked.
Here's my code. Thanks.
Visual Basic:
If Me.CheckedListBox1.CheckedItems.Count > 1 Then
Dim clbText As String
Dim i As Integer
For i = 0 To CheckedListBox1.Items.Count - 1
If Me.CheckedListBox1.GetItemCheckState(i) Then
clbText = CheckedListBox1.CheckedItems.Item(i)
'copies selected file to project folder
Dim strFileToSaveNoPath As String = System.IO.Path.GetFileNameWithoutExtension(clbText)
Dim strFileToSaveNoPathDWG As String = strFileToSaveNoPath & ".dwg"
strFileToSave = Me.dirStdDtl.Path & "\" & strFileToSaveNoPath & ".dwg"
Dim strNewFile As String = Me.proj_dir.Path & "\" & strFileToSaveNoPathDWG
Dim FileExists As Boolean = System.IO.File.Exists(strNewFile)
If FileExists = True Then
Dim msg As String = ("One or more detail(s) already exist in " & Me.proj_dir.Path & "." _
& vbCrLf & "Are you sure you want overwrite existing detail(s)?")
Dim Response As String = MsgBox(msg, MsgBoxStyle.OkCancel, "File(s) already exists")
Select Case Response
Case vbOK
IO.File.Delete(strNewFile)
System.IO.File.Copy(strFileToSave, strNewFile)
Case vbCancel
Exit Sub
End Select
Else
System.IO.File.Copy(strFileToSave, strNewFile)
End If
End If
Me.CheckedListBox1.SetItemCheckState(i, CheckState.Unchecked)
Me.CheckedListBox1.Refresh()
Next i
End If