?
Solved

Set focus to a variable in VB.Net

Posted on 2007-11-15
5
Medium Priority
?
979 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

741 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