Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Set focus to a variable in VB.Net

Posted on 2007-11-15
5
Medium Priority
?
980 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
vbturbo earned 1000 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 1000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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