Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
Edited 4-Feb-13 0:45am
RDBurmon9.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
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2014
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