Click here to Skip to main content
12,759,761 members (33,977 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
I have four textboxes and four buttons
how can I use one OpenFileDialog1 for 4 button controls..?

thanks

below is the code ..

Private Sub btn_ClientSelectTemplate_0_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_0.Click
      OpenFileDialog1.ShowDialog()
  End Sub

  Private Sub btn_ClientSelectTemplate_1_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_1.Click
      OpenFileDialog1.ShowDialog()
  End Sub

  Private Sub btn_ClientSelectTemplate_2_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_2.Click
      OpenFileDialog1.ShowDialog()
  End Sub

  Private Sub btn_ClientSelectTemplate_3_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_3.Click
      OpenFileDialog1.ShowDialog()
  End Sub

  Private Sub OpenFileDialog1_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
      '' --- Gives the full path of file name
      Me.txtClientProject_0.Text = OpenFileDialog1.FileName
      '' --- Gives only the file name
      'Me.txtClientProject_0.Text = Path.GetFileName(OpenFileDialog1.FileName)

  End Sub

  Private Sub OpenFileDialog2_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog2.FileOk
      txtClientProject_1.Text = OpenFileDialog2.FileName
  End Sub

  Private Sub OpenFileDialog3_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog3.FileOk
      txtClientProject_2.Text = OpenFileDialog3.FileName
  End Sub

  Private Sub OpenFileDialog4_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog4.FileOk
      txtClientProject_3.Text = OpenFileDialog4.FileName
  End Sub
Posted 4-Feb-13 0:33am
Updated 4-Feb-13 0:45am
RDBurmon10.1K
v3

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Why are you using separate event to populate text box for file name. Write the same after showdialog code in the same button event

see this


Private Sub btn_ClientSelectTemplate_0_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_0.Click
      OpenFileDialog1.ShowDialog()
     Me.txtClientProject_0.Text = OpenFileDialog1.FileName
      '' --- Gives only the file name
      'Me.txtClientProject_0.Text = Path.GetFileName(OpenFileDialog1.FileName)

  End Sub

  Private Sub btn_ClientSelectTemplate_1_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_1.Click
      OpenFileDialog1.ShowDialog()
  txtClientProject_1.Text = OpenFileDialog2.FileName
  End Sub

  Private Sub btn_ClientSelectTemplate_2_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_2.Click
      OpenFileDialog1.ShowDialog()
 txtClientProject_2.Text = OpenFileDialog3.FileName
  End Sub

  Private Sub btn_ClientSelectTemplate_3_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_3.Click
      OpenFileDialog1.ShowDialog()
 txtClientProject_3.Text = OpenFileDialog4.FileName
  End Sub

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100