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?
Re: Validate control type?
This is the correct syntax
Code:
if typeof me.activecontrol is textbox then
'DO SOMETHING
end if
Re: Validate control type?
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.