Results 1 to 3 of 3

Thread: [RESOLVED] Single event for multiple controls

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    17

    Resolved [RESOLVED] Single event for multiple controls

    TextBox1
    TextBox2
    TextBox3
    TextBox4

    ListBox1

    I have a list box with 10 items. I want that when the user focuses on any of those texboxes and double clicks on any item in the listbox, it inserts the selected value in the focused textbox.

    Can anyone help me please?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Single event for multiple controls

    When you double-click an item in the ListBox the TextBox will lose focus, so you are going to have to use a class-level variable to remember which TextBox was the last one to have focus.
    VB Code:
    1. Private lastFocusedTextBox As TextBox
    2.  
    3.     Private Sub RememberSelectedTextBox(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, _
    4.                                                                                                      TextBox2.Enter, _
    5.                                                                                                      TextBox3.Enter, _
    6.                                                                                                      TextBox4.Enter, _
    7.                                                                                                      TextBox5.Enter, _
    8.                                                                                                      TextBox6.Enter, _
    9.                                                                                                      TextBox7.Enter, _
    10.                                                                                                      TextBox8.Enter, _
    11.                                                                                                      TextBox9.Enter, _
    12.                                                                                                      TextBox10.Enter
    13.         Me.lastFocusedTextBox = DirectCast(sender, TextBox)
    14.     End Sub
    15.  
    16.     Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
    17.         Me.lastFocusedTextBox.Text = Me.ListBox1.GetItemText(Me.ListBox1.SelectedItem)
    18.     End Sub
    Last edited by jmcilhinney; Jan 8th, 2006 at 08:23 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    17

    Re: Single event for multiple controls

    wow.. thanks!!!!! I really appreciate it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width