I have a form in my project, which I open as a DialogBox. On that that
form there are 3 TextBoxes. To one of them I want to write in a file
path. To have it easier I have an OpenFileDialog control on my form.
Selected file path is written in to th TextBox. OpenFileDialog is open
by click on a Button.
There is other Button on the form run the code which save every form
field to a file.
When I manualy fill all fields in form everything is OK, but when i
choose the file path by mean of OpenFileDialog, nothing is save to the
file. Even file is not created. That happend when i confirm selected
file in OpenFileDialog, but if I press Cancel and than maualy fill the
TextBox in program saves data properly to file.
Where is the problem? And how can I solve it.
Code for the button which activate OpenFileDialog:
Private Sub btnLogFileSourceBrowse_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnLogFileSourceBrowse.Click
ofdFiles.Title = "Select log file"
ofdFiles.Multiselect = False
If ofdFiles.ShowDialog = Windows.Forms.DialogResult.OK Then
txtLogFileSource.Text = ofdFiles.FileName
End If
End Sub
Code for button whoch saves data
Private Sub btnProjectDetailsAccept_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnProjectDetailsAccept.Click
'Set True value indicating that form was submited...
AcceptedOnce = True
'Check form to find any empty fields. If every field is filled
process to save data...
If CheckIfFilled() = True Then
'Create a new project data...
Dim newProject As ProjectDataSettings
newProject =
LogTeller.frmLogTellerMain.ProjectsBook.AddProject DataSettings
'Set current number of elements in ProjectsBook as the
current index...
LogTeller.frmLogTellerMain.CurrentProjectIndex =
LogTeller.frmLogTellerMain.ProjectsBook.Items.Coun t
'Write data from form to project's properties...
UpdateCurrentProject(LogTeller.frmLogTellerMain.Cu rrentProject)
'Remove empty objects from collections...
LogTeller.frmLogTellerMain.ProjectsBook.RemoveEmpt y()
'If there is not any object in colection, add one empty...
If LogTeller.frmLogTellerMain.ProjectsBook.Items.Coun t = 0
Then LogTeller.frmLogTellerMain.ProjectsBook.AddProject DataSettings()
'Save data to file...
LogTeller.frmLogTellerMain.SaveChanges()
'Clear all fields in the form...
ClearForm()
'Close the form...
Me.Close()
AcceptedOnce = False
End If
End Sub
Code which copies date from form to object:
Public Sub UpdateCurrentProject(ByVal project As ProjectDataSettings)
'Copy data...
project.ProjectName = txtProjectName.Text
project.DomainName = txtDomainName.Text
project.LogFileSource = txtLogFileSource.Text
End Sub