Fill selected textbox

sduphily

New member
Joined
Nov 14, 2007
Messages
2
Programming Experience
1-3
I'm trying to do something that in my mind should be so simple, but my head must've took a vacation....

I have a dialog that has ten textboxes to store XML file paths, a Select button (opens OpenFileDialogXML), an OK and Cancel button.

What I want to have happen is that when the user selects the XML file in the OpenFileDialogXML and clicks OK, that the entry goes into the last selected textbox.
VB.NET:
Private Sub OpenFileDialogXML_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialogXML.FileOk
        'Need to select last textbox that had focus.
        Me.ActiveControl.Text = OpenFileDialogXML.FileName
    End Sub
The problem is that the Select button from the original dialog has focus when the OK button is selected. Any assistance with how to get the last textbox selected would be appreciated.

TIA
 
You can keep track of the last Textbox like this:
VB.NET:
Private lastTB As TextBox

Private Sub TBs_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.Leave, TextBox2.Leave, TextBox1.Leave
    Me.lastTB = CType(sender, TextBox)
End Sub

Private Sub btnSomething_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSomething.Click
    If Me.lastTB IsNot Nothing Then
        Me.lastTB.Text = Date.Now.ToString
    End If
End Sub
Another option could be to arrange the UI from the active Textboxes, for example with a context menu and/or keyboard shortcut to activate the dialog.
 
Back
Top