OpenFileDialog problem

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
On my main form I have a link label and a browse button. When the browse button is clicked, an OFD comes up, allows the user to select a file, and copys this file to the link label. Then I have the process set so when the user clicks on the link label, it opens the document stored within it.
Here's my code:
Private Sub btnRDBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRDBrowse.Click

Dim xRD As New OpenFileDialog
With xRD
.InitialDirectory = "s:\"
.Title = "Browse for Response Documentation"
If .ShowDialog = DialogResult.OK Then
txtResponseDoc.Text = .FileName
End If
End With
End Sub

The above code works fine and when submitted to the DB, the location that is in the link label is sent to the field OK, e.g. s:\IT\test1.doc

I have a datagrid (read only) with child data that only displays a summary of ID, Name and Town. When the user clicks another button, it brings up a modal form with all of the information from the table, i.e. ID, Name, Add1, Add2, Town, City, etc

I have another OFD sub like above for another text field, and this works OK in the sense it copies the file to the textbox, and then the user can click and it opens OK etc.
But when updated, the text in this box is not sent back to the DB. However, if I manually type any text into this box and Update, the data is submitted back to the DB, thus proving that there are no errors with my data bindings.

This has now got me properly confused - is it something to do with the OFD not liking modal forms? Basically on the button that opens all the information on the modal form, it uses currencyManager to pull all of the information for that record selected in the dataGrid, and then on the form, when the user clicks Update or Cancel, it uses either cm.endcurrenctedit or cm.cancelcurrentedit.

I can only assume this is the problem - has anyone got any ideas, - maybe I have to use the OFD component instead of writing it at runtime?

Cheers guys, something for the weekend :)
Luke
 
Hi Kulrom - the 2nd OpenFileDialog is on a modal form.

The 1st is on the main form and works OK. On this form is a datagrid, and upon clicking a button, a modal form displaying all of the info appears based on the record selected in the datagrid.
On this form, the 2nd OpenFileDialog is. Clicking on btnBrowse opens OpenFileDialogOK, and selecting a file then copies it to the textbox. Upon clicking OK (which runs cm.endcurrentedit) all of the data in the textboxes is sent back to the database, apart from the textbox with the file from OpenFileDialog.

However, if I open the form, and manually type in that textbox and then click OK, the data is sent back to the database.

Hope that makes more sense.

Thanks,
Luke
 
Ok - if I understand you correctly, the filename property is supposed to
pass the value to the shared textBox or label control within main form ...

As long as you want to save/insert data from within main form you need to declare object with Public Shared scope that will accept value/s from other forms:

Public Shared myTxt As TextBox ....

later from modal form:


Dim someVar as String = OFD.FileName
MainForm.myTxt.Text = someVar

btw, i'm still not sure what you want to acomplish there ... sorry :(

Cheers ;)
 
Think I'm confusing you with the bit about the main form!!!

If you look at Image4 that shows the first page of my form. There is a header "Documentation", a textbox and a "Browse" button.
This button opens OFD. This is OK, no problems.

Image 5 shows the second page of my form, with a datagrid and then a revision info button. When a record is selected in the datagrid (only shows a couple of fields) and this button pressed, a modal form (Image 6) appears with all information on that record.

One of these is "Feedback Documentation", with a textbox and a browse button. The code of the button is set exactly the same as that of the browse button in Image 4 (apart from where the name of the textbox where the filename appears).

However, even though this filename appears in the "Feedback Documentation" textbox, when I click Update (which runs cm.endcurrentedit), that value is not updated to the DataSet.
BUT - If I manually type a value in that textbox by clicking in it and typing say, s:\IT\Test.doc and then clicking Update, the value of that textbox IS updated to the DataSet.

Therefore I'm thinking it must be an issue with the OFD rather than the bindings, as manually typing updates OK.

Hope that's more helpful!!!!

Regards,
Luke
 

Attachments

  • Image4.jpg
    Image4.jpg
    61.8 KB · Views: 165
  • Image5.jpg
    Image5.jpg
    35.4 KB · Views: 168
  • Image6.jpg
    Image6.jpg
    62.2 KB · Views: 164
Well, i must say you clarified some points that maybe were still a little cloudy for me ... :)

Hmm ... very strange situation :( but it really doesn't matter either modal or modeless form as you can see the text/path&filename passed from openFileDialog ... (can you see the text from OFD within textbox?

I really have no other idea ... without see the code :(

Cheers ;)
 
Thanks for the reply. Being new 'n all I kind of confuse people when asking questions, still trying to figure out how to word them correctly in programming terms!!

Here's the code for the modal form:

VB.NET:
[size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Class[/color][/size][size=2] frmRevisionInfo
[/size][size=2][color=#0000ff]Inherits[/color][/size][size=2] System.Windows.Forms.Form
 
[/size]Dim dsDWR As dsDWR 
 
Dim drvDetail As DataRowView
 
Dim dvDetail As DataView
 
Public Sub RevInfo(ByVal cm As CurrencyManager)
 
drvDetail = CType(cm.Current, DataRowView)
 
dvDetail = drvDetail.DataView
 
dsDWR = CType(dvDetail.Table.DataSet, dsDWR)
 
'open the form bound to the revision selected in the main form
 
Me.BindingContext(dvDetail).Position = cm.Position
 
'bind the textboxes to columns from DataView and make them readonly
 
txtResponse.DataBindings.Add("Text", dvDetail, "Response")
 
txtResponse.ReadOnly = True
 
txtResponseDoc.DataBindings.Add("Text", dvDetail, "ResponseDocumentation")
 
txtResponseDoc.Enabled = True
 
With txtFeedback
 
.DataBindings.Add("Text", dvDetail, "CustomerFeedback")
 
.ReadOnly = True
 
End With
 
With txtFeedbackdoc
 
.DataBindings.Add("Text", dvDetail, "FeedbackDocumentation")
 
.Enabled = True
 
End With
 
With dtpCreatedDate
 
.DataBindings.Add("Text", dvDetail, "CreatedDate")
 
.Enabled = False
 
End With
 
With cboCreatedBy
 
.DataBindings.Add("SelectedValue", dvDetail, "CreatedBy")
 
.Enabled = False
 
End With
 
If Me.ShowDialog = DialogResult.OK Then
 
cm.EndCurrentEdit()
 
Else
 
cm.CancelCurrentEdit()
 
End If
 
End Sub
 
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
 
DialogResult = DialogResult.OK
 
End Sub
 
Private Sub btnAddFeedback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddFeedback.Click
 
txtFeedback.ReadOnly = False
 
txtFeedbackdoc.Enabled = False
 
btnAddFeedback.Enabled = False
 
btnClose.Enabled = False
 
btnOK.Enabled = True
 
btnCancel.Enabled = True
 
btnFDBrowse.Enabled = True
 
End Sub
 
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
 
Me.Close()
 
End Sub
 
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
 
DialogResult = DialogResult.Cancel
 
End Sub
 
Private Sub frmRevisionInfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
btnCancel.Enabled = False
 
btnOK.Enabled = False
 
btnFDBrowse.Enabled = False
 
End Sub
 
Private Sub btnFDBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFDBrowse.Click
 
Dim x As New OpenFileDialog
 
With x
 
.InitialDirectory = "s:\"
 
.Title = "Browse for Feedback Documentation"
 
If .ShowDialog = DialogResult.OK Then
 
txtFeedbackdoc.Text = .FileName
 
End If
 
End With
 
End Sub
 
Private Sub txtFeedbackdoc_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles txtFeedbackdoc.LinkClicked
 
Dim strDoc As String
 
strDoc = txtFeedbackdoc.Text
 
Process.Start(strDoc)
 
End Sub
 
End Class

But nothing in there I can see to cause the problem!!!

thanks again,
Luke
 
Hi Kulrom,

Wondered if you've had a chance to look at the code yet?

I'm still well confused with this - spent 4 hours solid looking at it over the weekend and I cannot for the life of me figure out why it's not sending the text back, even though it's displaying it...

Cheers,
Luke
 
Hi Luke,
Sorry for the delay ... i was in big rush these days :rolleyes:

About the code; i couldn't find anything buggy with your code ... everything seems fine to me. Especially that it doesn't throw an exception or an error ... It could be caused by many factors but however if i was you i would try to assure that string is there ... means i'd put an if statement that would check the text property of txtFeedbackdoc textbox.


Cheers ;)




http://www.developerfusion.co.uk/forums/topic.aspx?id=27032&action=showlast
 
Back
Top