|
-
May 30th, 2006, 10:56 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] OOP classes question about inheritance , Special Case in Here !!
Dear all,
i have a situation in which i loop through the controls of a form.
i need to get the controls who is inherited from textbox or is a textbox itself
i have tried the following code
VB Code:
for each ctl as control in frmx.controls
if typeof ctl is textbox then
'do something
end if
next
this code works only for original textbox controls, but if i have controls that inherits from the textbox, it won't be collected
so i tried other code, like this
VB Code:
for each ctl as control in frmx.controls
if ctl.gettype.isassignablefrom(gettype(textbox)) then
' do something
end if
next
this give me only the inherited , not both !!!
i have also tried this code
VB Code:
for each ctl as control in frmx.controls
If ctl.GetType.BaseType Is (GetType(textBox)) Then
'do anything
End If
next
this code works for only the inherited controls, but the original textbox do not work.
how can i set a condition to gather all textboxes and all controls who inherits from textbox. i dont want to use and / or operators as the code already is very heavy and complicated and recursive. it is driving me crazy already
thx in advance
-
May 30th, 2006, 11:03 AM
#2
Frenzied Member
Re: OOP classes question about inheritance , Special Case in Here !!
VB Code:
for each ctl as control in frmx.controls
if typeof ctl is textbox OrElse ctl.gettype.isassignablefrom(gettype(textbox)) then
'do something
end if
next
oh nevermind.... Just finished reading the end
-
May 30th, 2006, 11:05 AM
#3
Re: OOP classes question about inheritance , Special Case in Here !!
Why not add them together with an OR or an OrElse?
If control is textbox OR control is assignable from textbox then
**EDIT - same edit as mpdeglau
-
May 30th, 2006, 11:09 AM
#4
Re: OOP classes question about inheritance , Special Case in Here !!
here is your one liner
VB Code:
For Each ctl As Control In Me.Controls
If GetType(TextBox).IsInstanceOfType(ctl) Then
messagebox.show(ctl.Name)
End If
Next
-
May 30th, 2006, 12:37 PM
#5
Thread Starter
Frenzied Member
Re: OOP classes question about inheritance , Special Case in Here !!
thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaank you
i knew the soltuion is possible
thank you again kleinma
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
|