DiverDan
Well-known member
I am calling a LoadListview sub to open and Deserialize a binary file. The openfile dialog is as follows:
and the LoadListview sub is:
openFile.Close() is not closing and prevents any other files to be opened and displayed. Why is openFile.Close() not closing?
Thanks
Code:
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.Filter = "Electric Calculator (*.elc)|*.elc|Binary (*.bin)|*.bin"
OpenFileDialog1.DefaultExt = "elc"
OpenFileDialog1.AddExtension = True
If OpenFileDialog1.ShowDialog() = DialogResult.Cancel Then Exit Sub
worksheetName = OpenFileDialog1.FileName
LoadListview(OpenFileDialog1.FileName)
and the LoadListview sub is:
Code:
Sub LoadListview(ByVal fname As String)
Dim formatter As New BinaryFormatter()
Dim openFile As FileStream
openFile = File.Open(fname, FileMode.Open)
Dim ListViewItems As New ArrayList()
ListViewItems = CType(formatter.Deserialize(openFile), ArrayList)
Dim itm As Integer
lvData.Items.Clear()
Dim lvItem As ListViewItem
For itm = 0 To ListViewItems.Count - 1
lvItem = New ListViewItem()
lvItem = ListViewItems(itm)
lvData.Items.Add(lvItem)
Next
openFile.Close()
End Sub
openFile.Close() is not closing and prevents any other files to be opened and displayed. Why is openFile.Close() not closing?
Thanks
Last edited by a moderator: