[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 981
  • Last Modified:

Set focus to a variable in VB.Net

I have a seried of textboxes which I would like the user to click on the select a date from a date/time picker then return the date to the textbox which was last clicked.

I can set a variable to the textbox which was clicked in the Enter event thus:-

Private Sub TxHaulier_Leave(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles TxHaulier1.Leave, TxHaulier3.Leave, TxHaulier2.Leave
        Dim TB As TextBox = sender
        ControlClicked = tb.name
        datetimepicker.focus
End Sub

What I want is something in the datetimepicker click or valuechanged event to return the value to ColtrolClicked

Any ideas?
0
grwallace
Asked:
grwallace
  • 2
  • 2
2 Solutions
 
vbturboCommented:
try this

    Dim TB As Object

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        TB.Text = DateTimePicker1.Value.ToShortDateString()
    End Sub

    Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
        TB = sender

    End Sub
    Private Sub TextBox2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Leave
        TB = sender

    End Sub

vbturbo
0
 
VBRocksCommented:
Create a Module level variable to store which textbox was selected:

Private mTextBox as TextBox = Nothing

'Use the Enter event of each textbox to set the module level variable:
Private Sub TxHaulier_Enter(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles TxHaulier1.Enter, TxHaulier3.Enter, TxHaulier2.Enter

    mTextBox = sender

End Sub

'Use DataTimePicker ValueChanged event to set it for the textbox:
    Private Sub DateTimePicker1_ValueChanged( _
          ByVal sender As System.Object, ByVal e As System.EventArgs) _
          Handles DateTimePicker1.ValueChanged

         mTextBox.Text = DirectCast(sender, DateTimePicker).Value
    End Sub



0
 
VBRocksCommented:
Oh, I apologize for dupping you vbturbo.  I didn't see your post until after I posted.
0
 
vbturboCommented:
no problem ..... _;) welcome in
0
 
grwallaceAuthor Commented:
Excellent
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now