Solved

Checking if a control exists within a container control?

Posted on 2013-11-14
6
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 86

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 86

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:BlakeMcKenna
ID: 39649345
Ok,

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

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…

740 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