OpenFileDialog Mystery

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Kulrom tried helping with this a while back, but between us it remained an unsolved mystery. I've decided to resurrect it to see whether anyone else has had the problem, or whether anyone knows the answer.

Here's the scenario:

When a user selects a row in a datagrid, and presses "Info", currency manager opens the information about that row displayed as a form. This was taken from MS ADO.Net book by David Sceppa.

Here is the code for the button:

VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] frm [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] frmAddResponse
 
frm.RevAdd(cmRevision)
 
frm.Dispose()
 
[/size]

Here is the the RevAdd code on the form:

VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] dsDWR [/size][size=2][color=#0000ff]As[/color][/size][size=2] dsSearchDWR
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] drvDetail [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataRowView
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] dvDetail [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataView
 
[/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] RevAdd([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] cm [/size][size=2][color=#0000ff]As[/color][/size][size=2] CurrencyManager)
 
drvDetail = [/size][size=2][color=#0000ff]CType[/color][/size][size=2](cm.Current, DataRowView)
 
dvDetail = drvDetail.DataView
 
dsDWR = [/size][size=2][color=#0000ff]CType[/color][/size][size=2](dvDetail.Table.DataSet, dsSearchDWR)
 
[/size][size=2]txtResponseHeader.Focus()
 
[/size][size=2][color=#008000]'open the form bound to the revision selected in the main form
 
[/color][/size][size=2][color=#0000ff]Me[/color][/size][size=2].BindingContext(dvDetail).Position = cm.Position
 
[/size][size=2]txtResponseHeader.DataBindings.Add("Text", dvDetail, "ResponseHeader")
 
txtResponse.DataBindings.Add("Text", dvDetail, "Response")
 
txtResponseDoc.DataBindings.Add("Text", dvDetail, "ResponseDocumentation")
 
[/size][size=2][color=#0000ff]If [/color][/size][size=2][color=#0000ff]Me[/color][/size][size=2].ShowDialog = DialogResult.OK [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2]cm.EndCurrentEdit()
 
[/size][size=2][color=#0000ff]Else
 
[/color][/size][size=2]cm.CancelCurrentEdit()
 
[/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub[/color][/size]
 
[size=2][color=#0000ff]
[/color][/size]

Heres the problem:

txtResponseDoc is a link label. The user presses another button, and an OpenFileDialog appears. The user selects the file they want (only one file) and when they click OK, the string of the file location is stored in the link label. I.E. \\Server1\Downloads\VBNet\solution.doc
The link label then has the ability to click and go to that file.

The code for the button is:

VB.NET:
Dim x as new OpenFileDialog
[size=2][color=#0000ff]If[/color][/size][size=2] x.ShowDialog = DialogResult.OK [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2]txtResponseDoc.Text = x.FileName
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
[/color][/size]

This works fine.

HOWEVER....As soon as the user clicks Update on the form, and this runs showDialog = DialogResult.OK and the form closes, all of the data appears in the datagrid appart from the documentation filename

Now for the weird bit....If I replace the linkLabel with a textBox, and type anything in there, it is updated to the datagrid.

Obviously this means that the problem is with the OFD. I've tried changing the way the form is to;
If Me.ShowDialog = DialogResult.Yes

In case it was because the two DialogResult.OK 's were conflicting. This still didn't work.

Other than passing this across to Microsoft themselves, does anyone have any ideas?

Regards,
Luke

 
Best I can think of is that because the link label is a read only (can't be edited by the user) it doesn't fire off the necessary event(s) for the databinding to update the source datatable.

That's the best I can come up with that makes sense to me.

Tg
 
I forgot to add on the original post - I have exactly the same set-up (coding etc) on another form which updates and works fine.

I've tested and it also works if another form is opened modal (.showdialog) - but then it doesn't bind itself to the selected row in the datagrid, hence why I use the currency manager.

Is there another way to bind the form to the selected row in the datagrid? The form displays all the information of that table, whilst the datagrid only shows a summary.
I.E:
DataGrid: Rev Number, Response Header, RS Date, Feedback Header, FB Date.

From: Development Number, Rev Number, Response Header, Response, Response Created By, RS Date, Feedback Header, Feedback, Feedback Created By, FB Date.

If there is another way of binding the selected row to show the relevant data on the form then I will try it that way. I've got a feeling it's a conflict between currency manager opening the form and a open file dialog for whatever reason.

Luke
 
Try passing your currency manager byref instead of byval.

Tg
 
Actually that never solved it fully. I've just made a blag that fixes it...

I thought I'd set link labels but they are actually text boxes (I'd changed the form).
If I browse to a document, add the filename to the textbox, then click Update, the filename is not updated to the datagrid.

However, if I do the same, but after the filename appears in the textbox, I click in the textbox, and then click Update, the filename is.

I've set it so that txtFeedbackDoc takes Focus after the OpenFileDialog is closed....
 
Weird.... I wonder if it uses the LostFocus event to trigger off the change.... seems like it should be using the Change event instead.

The difference between Ref & Val is fairly simple. It determines if a copy of the value of the object/variable (byval) is passed or if a pointer to the object/variable (byref) is passed. When passed byVal, any changes to that variable is limited to that sub/func in scope. IE, when it comes back out to the calling code, the original value of the variable will be restored. If it's passed byRef, then any changes to it will be carried back out to the calling code.

Tg
 
Back
Top