Search code examples
visual-studio-2010automationopenfiledialog

make label update on file directory change (visual basic)


When I use an OpenFileDialog, and select a file and click open etc, etc...

I want a label on the same form to automatically update with the directory path. At the moment I have this working, However the label updates on click, not automatically on the directory change.

CODE:

Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    Label4.Text = OpenFileDialog2.FileName

End Sub

Cna I change the "Label4_Click" to something else for an auto update?


Solution

  • How are you displaying the OpenFileDialog? You need to update the Label from there!...

    Something like:

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If OpenFileDialog2.ShowDialog = Windows.Forms.DialogResult.OK Then
            Label4.Text = OpenFileDialog2.FileName
        End If
    End Sub