Solved

Set focus to a variable in VB.Net

Posted on 2007-11-15
5
976 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 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