OpenFileDialog, InitialDirectory

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Okay,

Three TextBox's, Three Buttons. Each with a Unique Identifier on the Tag property, THe Buttons all point to the same Click event, because they All open up a OpenFileDialog().

VB.NET:
	Sub OpenClick(ByVal Sender As Object, ByVal e As EventArgs)
		Dim b As Button = sender
		Dim sSrc As String = ""
		If (b IsNot Nothing) Then
			OpenFileDlg.Filter = "Executables (*.exe;*.lnk)|*.EXE;*.LNK"
			Select Case CInt(b.Tag)
				Case 6, 11: OpenFileDlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
				Case 10: OpenFileDlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Programs)
			End Select
			If OpenFileDlg.ShowDialog(Me) = DialogResult.OK Then
				Select Case CInt(b.Tag)
					Case 6: TextBox1.Text = OpenFileDlg.FileName
					Case 10: TextBox2.Text = OpenFileDlg.FileName
					Case 11: TextBox3.Text = OpenFileDlg.FileName
				End Select
			End If
		End If
	End Sub

My problem is this:

When I click the button with Tag=5, it sets the initial directory of the dialog box and all is well. I may change directories within the dialog, select the file I want a click OK.

However, when I click a different button on the from, say Tag=10, it is supposed to change the InitialDIrectory, and stepping through the code it does reset the property correctly, but when the dialogbox opens it doesn't reflect that change.

WHy?
THanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 
This will reset dialog to initial directory:
VB.NET:
OpenFileDialog1.FileName = ""
 
Back
Top