|
-
Nov 12th, 2003, 08:12 AM
#1
Thread Starter
New Member
Error Handling for OpenDialog
I am trying to put up an error MessageBox when the user clicks Open without defining a file to open. In the code below, the Error box does show up until after you close the OpenDialog window. I am trying to make it so that if nothing is selected, the Error Box is displayed, more as a warning. When the Message box comes down, the User can enter a file to open. Something is wrong in this code. Any guesses what it is?
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
'The following section of code displays the directory tree and displays the
'selected filename in the textbox.
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
'put filename in textbox1
FileName.Text = OpenFileDialog1.FileName
'open file
ElseIf Not OpenFileDialog1.ShowDialog() = DialogResult.OK Then
MessageBox.Show("Choose a file to Open", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Dim sr As New IO.StreamReader(New IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open))
FullText.Text = sr.ReadToEnd
'Reads the entire file using StreamReader, and puts it in a textbox.
sr.Close()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|