Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Getting Child controls from a user control CF 2.0

Hybrid View

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

    Re: [2005] Getting Child controls from a user control CF 2.0

    How is your 'uc' variable declared because this:
    vb.net Code:
    1. tp.Controls(0)
    will only return a Control reference. If you've declared 'uc' as type Control then you won't get Intellisense because the Control class doesn't have a TextProperty property. If you have declared 'uc' as the correct type then you must have Option Strict turned Off or this:
    vb.net Code:
    1. uc = tp.Controls(0)
    wouldn't compile.

    I'd rather see safer code like this:
    vb.net Code:
    1. For Each page As TabPage In Me.tbcTasks.TabPages
    2.     For Each ctl As Control In page.Controls
    3.         If TypeOf ctl Is MyUserControl Then
    4.             MessageBox.Show(DirectCast(ctl, MyUserControl).TextProperty)
    5.             Exit For
    6.         End If
    7.     Next ctl
    8. Next page
    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

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: [2005] Getting Child controls from a user control CF 2.0

    Hello,

    Thanks for the example code you have given me.

    Yes, i know my mistake i was declaring like this. Option strict turned ON

    Code:
    dim uc as control
    No wonder it didn't work.

    My user controls is called PDATaskControl.ViewTasks

    I have declared like this
    Code:
    dim uc as PDATaskControl.ViewTask
    'Shouldn't I be able to do something like this
    uc tp.controls(0)'The index should give me the user control as it is the same type
    Thanks again,
    steve

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