I have a question, maybe it's a stupid question, but on the form event: FormClosing I have this code that saves a treeview to xml, when it is saved it displays a message, but when I click the messagebox OK button, the messagebox keeps popping up and won't close that form.
Here is the code I use:
What I even tried is putting the code between: try catch
but the response remains the same.
Thanks
Here is the code I use:
VB.NET:
Private Sub AddressBook_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
'Build our List of custom objects from our TreeView's Nodes
Dim myNodes = BuildMyNodes(TreeView1.Nodes)
'Serialize object to a text file.
Dim objStreamWriter As New StreamWriter(Application.StartupPath + "\addressbook.xml")
Dim x As New XmlSerializer(myNodes.GetType)
x.Serialize(objStreamWriter, myNodes)
objStreamWriter.Close()
MessageBox.Show("Addressbook saved!")
Close()
End Sub
What I even tried is putting the code between: try catch
VB.NET:
Try
'Build our List of custom objects from our TreeView's Nodes
Dim myNodes = BuildMyNodes(TreeView1.Nodes)
'Serialize object to a text file.
Dim objStreamWriter As New StreamWriter(Application.StartupPath + "\addressbook.xml")
Dim x As New XmlSerializer(myNodes.GetType)
x.Serialize(objStreamWriter, myNodes)
objStreamWriter.Close()
MessageBox.Show("Addressbook saved!")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Close()
Thanks