A
Andrew
created a custom class that is derived from TreeNode, let's call it
customTreeNode. I'm trying to use the TreeViewEventArgs (for the
AfterSelect event) but I cannot cast to my derived TreeNode. Here is
a snip...
---code snip---
private void _TreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
customTreeNode foo = (customTreeNode)e.Node;
displayInfo(foo);
}
private void displayInfo(customTreeNode cTreeNode) {
//code
}
---code snip---
Following the example from MSDN,
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html
/vbtsksubclassinglistitemortreenode.asp),
the MSDN example (at the bottom of the page) is almost exactly like
the above code.
At runtime, I get a InvalidCastException. What gives?
In the AfterSelect event handler method, if I do
'e.Node.GetType()'--it is, in fact, a customTreeNode. If I do not
attempt to cast to a customTreeNode and just try to pass it to
displayInfo, I get a compilation error because the compiler thinks
that e.Node is TreeNode, not a customTreeNode (expected).
Am I casting incorrectly? Is this a bug? Is the documentation shoddy?
Thanks,
Andrew
customTreeNode. I'm trying to use the TreeViewEventArgs (for the
AfterSelect event) but I cannot cast to my derived TreeNode. Here is
a snip...
---code snip---
private void _TreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
customTreeNode foo = (customTreeNode)e.Node;
displayInfo(foo);
}
private void displayInfo(customTreeNode cTreeNode) {
//code
}
---code snip---
Following the example from MSDN,
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html
/vbtsksubclassinglistitemortreenode.asp),
the MSDN example (at the bottom of the page) is almost exactly like
the above code.
At runtime, I get a InvalidCastException. What gives?
In the AfterSelect event handler method, if I do
'e.Node.GetType()'--it is, in fact, a customTreeNode. If I do not
attempt to cast to a customTreeNode and just try to pass it to
displayInfo, I get a compilation error because the compiler thinks
that e.Node is TreeNode, not a customTreeNode (expected).
Am I casting incorrectly? Is this a bug? Is the documentation shoddy?
Thanks,
Andrew