Solved

Set focus to a variable in VB.Net

Posted on 2007-11-15
5
967 Views
Last Modified: 2013-11-26
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
Comment
Question by:grwallace
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
vbturbo earned 250 total points
ID: 20290798
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
 
LVL 27

Assisted Solution

by:VBRocks
VBRocks earned 250 total points
ID: 20290839
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
 
LVL 27

Expert Comment

by:VBRocks
ID: 20290890
Oh, I apologize for dupping you vbturbo.  I didn't see your post until after I posted.
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20290902
no problem ..... _;) welcome in
0
 

Author Closing Comment

by:grwallace
ID: 31409373
Excellent
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now