Results 1 to 4 of 4

Thread: Validate control type? [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Validate control type? [Resolved]

    Hey all,

    I wanted to find out a way to validate what kind of control the user is currently in. Is there a method of saying

    if me.activecontrol = Textbox then x

    I tried doing that but then it yells at me saying that "textbox is an object" blah blah. I understand that, I want to verify that the user is in a textbox and not a combobox or list box

    any suggestions?
    Last edited by Ogmius; Aug 17th, 2007 at 02:36 PM.
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Validate control type?

    This is the correct syntax

    Code:
    if typeof me.activecontrol is textbox then
        'DO SOMETHING
    end if

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: Validate control type?

    awsome thanks!
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

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

    Re: Validate control type? [Resolved]

    Note that you can also do this in VB 2005+:
    vb.net Code:
    1. Dim tb As TextBox = TryCast(Me.ActiveControl, TextBox)
    Which is the better choice depends on the situation but if you actually need to use the active control as its actual type then you should use TryCast. There's not much point using TypeOf and DirectCast together when you can just use TryCast alone.
    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

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