|
-
Aug 17th, 2007, 02:10 PM
#1
Thread Starter
Hyperactive Member
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..."
-
Aug 17th, 2007, 02:22 PM
#2
Re: Validate control type?
This is the correct syntax
Code:
if typeof me.activecontrol is textbox then
'DO SOMETHING
end if
-
Aug 17th, 2007, 02:36 PM
#3
Thread Starter
Hyperactive Member
Re: Validate control type?
"I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."
-
Aug 17th, 2007, 10:24 PM
#4
Re: Validate control type? [Resolved]
Note that you can also do this in VB 2005+:
vb.net Code:
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|