Solved

Checking if a control exists within a container control?

Posted on 2013-11-14
6
334 Views
Last Modified: 2013-11-14
I have a routine that changes various properties of controls. Within this routine, I need to check each control that is passed into it whether or not they are contained within a control. I'm sure this can be done but I've never done it before and don't know how to check for it.

Thanks!
0
Comment
Question by:BlakeMcKenna
  • 3
  • 3
6 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39648896
What issue(s) are you having with controls that are not contained by something?...we need more details to even begin to help with this one as it's too vague.
0
 

Author Comment

by:BlakeMcKenna
ID: 39649037
I'm trying to set the background color of a control that resides within a container control to the container control's background color.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39649097
Well, that would be difficult to do if said control doesn't have a container!  =)

You can check the Parent() property to see if it has a value.  It it is Nothing, then no container is set:
        If Not IsNothing(ctl.Parent) Then
            ' ... control has a container ...
        Else
            ' ... control does NOT have a container ...
        End If

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:BlakeMcKenna
ID: 39649345
Ok,

With the above code, how can I extract the Parent's BackColor or DefaultBackColor value?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39649500
?...Control.Parent() returns type Control.  Just access it!

Assuming it is not Nothing:
ctl.BackColor = ctl.Parent.BackColor

Open in new window

0
 

Author Closing Comment

by:BlakeMcKenna
ID: 39649570
Thanks...that worked!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now