Determing if an object is a parent of another object

K

kurotsuke

I've subclassed the TreeNode class and created:

NodeAbstract : TreeNode

NodeFolder : NodeAbstract
NodeFile : NodeAbstract

The nodes have been added to a Treeview.
Now, I would like to do a drag and drop between nodes inside the
treeview.

I reference all the nodes with the type NodeAbstract although the
nodes are of type NodeFile or NodeFolder.

When I do the drag and drop I use the following code

if (e.Data.GetDataPresent("NodeAbstract"))
//DO something


but it doesn't work because the node is of type NodeFolder or
NodeFile.

How can I solve the problem? I need the code to be executed if the
element inherits from NodeAbstract.
Thanks a lot.
 
S

Shakir Hussain

First check the type

if(treeNode.GetType().BaseType.ToString() == "NodeAbstract")
{
//do something
}
 
J

John Wood

You may have to just get the data instead, as an object, and then check to
see if it's of that type (eg. if (obj is NodeAbstract) ...)
 
J

John Wood

ew that's terrible.. if that was what he was trying to do, a much cleaner
approach would be:
if (treeNode is NodeAbstract)
{
...
}

But it's not... he wants to see the type of the data in the drop operation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top