473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to get ancestor's type?

I can check if a control is inherited from TabControl like this:

if (c.GetType().ToString() == "System.Windows.Forms.TabControl")

But what if c is inherited from TabControl? How to check that?

Thank you
Nov 16 '05 #1
2 2646

"Alex K." <Al***@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
I can check if a control is inherited from TabControl like this:

if (c.GetType().ToString() == "System.Windows.Forms.TabControl")

But what if c is inherited from TabControl? How to check that?


The operator "is".

if (c is System.Windows.Forms.TabControl )
{
}
David
Nov 16 '05 #2
Alex K. <Al***@discussions.microsoft.com> wrote:
I can check if a control is inherited from TabControl like this:

if (c.GetType().ToString() == "System.Windows.Forms.TabControl")

But what if c is inherited from TabControl? How to check that?


That's a really bad way of checking - and it's what the is and as
operators are for:

if (c is TabControl)
{
....
}

or

TabControl tc = c as TabControl;
if (tc != null)
{
...
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eshrath | last post by:
Hi, I have an xsl where a particular child node (<sub1> and <sub2> )can occur in two type of parent nodes (<A> and <B>). like <A> <sub1>11</sub1> <sub2>22</sub2>
1
by: Colin Fox | last post by:
Hi, all. Within an xsl template, you can use the <xsl:attribute> tag to set an attribute of the current output node. This is great. However, I need to be able to set an attribute of an...
2
by: Jesper | last post by:
Hi, Is it possible to query an object for an ancestor. I.e. determine if an object is derived from a certain type of class. thanx. Jespr.
3
by: Jack Addington | last post by:
Is there a quick and easy way in Visual Studio 2003 to get the method declaration from the ancestor so I can override/extend it? I know that if I am in another method or the constructor and type...
11
by: John Bailo | last post by:
Is anyone familar with the correct syntax for using ancestor:: ? I am trying to use it in a c# application, and I am also testing it in a parser application called Cooktop (...
2
by: werD | last post by:
Hello, Im wondering about using xml to store relational data. It works well with .net but im having some trouble with the xsl/xpath. Lets say that I have an xml like <data> <files> <file...
3
by: Luis P. Mendes | last post by:
Hi, I have the following problem: I instantiate class Sistema from another class. The result is the same if I import it to interactive shell. s = Sistema("par") class Sistema:
3
by: Valvalis | last post by:
Hello, I am trying to set a class attribute of a text.item element to the value of its nearest ancestor. I want to do this in the case that the class of the text.item is currently a blank string....
6
by: kishjeff | last post by:
Hi. Can someone tell me how to find all the elements of type 'table' which have an attribute named 'source' and are not descendents of 'querybox' ? I'm sort of wrestling with it and am hoping...
7
by: Ebenezer | last post by:
Hello! Let's suppose we have an XML with some nested NODE nodes: <root attr="first"> <node id="1" attr="mike"> <node id="2" /> <node id="3" attr="dave" /> </node> <node id="4">
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.