Results 1 to 5 of 5

Thread: [RESOLVED] OOP classes question about inheritance , Special Case in Here !!

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Resolved [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:
    1. for each ctl as control in frmx.controls
    2. if typeof ctl is textbox then
    3. 'do something
    4. end if
    5. 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:
    1. for each ctl as control in frmx.controls
    2. if ctl.gettype.isassignablefrom(gettype(textbox)) then
    3. ' do something
    4. end if
    5. next

    this give me only the inherited , not both !!!

    i have also tried this code

    VB Code:
    1. for each ctl as control in frmx.controls
    2.   If ctl.GetType.BaseType Is (GetType(textBox)) Then
    3.   'do anything
    4.   End If
    5. 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

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: OOP classes question about inheritance , Special Case in Here !!

    VB Code:
    1. for each ctl as control in frmx.controls
    2. if typeof ctl is textbox OrElse ctl.gettype.isassignablefrom(gettype(textbox)) then
    3. 'do something
    4. end if
    5. next


    oh nevermind.... Just finished reading the end
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  3. #3
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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

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

    Re: OOP classes question about inheritance , Special Case in Here !!

    here is your one liner

    VB Code:
    1. For Each ctl As Control In Me.Controls
    2.             If GetType(TextBox).IsInstanceOfType(ctl) Then
    3.                 messagebox.show(ctl.Name)
    4.             End If
    5.         Next

  5. #5

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: OOP classes question about inheritance , Special Case in Here !!

    here is your one liner
    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
  •  



Click Here to Expand Forum to Full Width