Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2007

Tip: Looking for answers? Try searching our database.

Extended TreeNode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hakan Ugur - 14 Dec 2007 17:10 GMT
Hi All,
I got a treeview object. I extended its TreeNodes to ExTreeNode and then
added ExTreeNode to Treeview control and binded to screen. And then, when I
try to read treeview it returns TreeNode instead of ExTreeNode. When I try
to cast to ExTreeNode, it throws Invalid Cast Exception.

Have you got any idea?

Thanks.
Peter Duniho - 14 Dec 2007 19:10 GMT
> Hi All,
> I got a treeview object. I extended its TreeNodes to ExTreeNode and then
[quoted text clipped - 5 lines]
>
> Have you got any idea?

Yes.  Clearly whatever ExTreeNode instance you've created, that's not  
what's in the TreeView where you "read" it.

Beyond that, without you posting a concise-but-complete sample of code  
that reliably reproduces the problem, there's no way to know for sure what  
you've done wrong.

Pete
Hakan Ugur - 17 Dec 2007 09:36 GMT
Ok, here the code.

public class ExtendedTreeNode:TreeNode
{
   private DateTime _CreationDate;

   public DateTime CreationDate{
       get{
               return _CreationDate;
        }set{
             _CreationDate=value;
       }

   }
}

And this is WebForm which is contains TreeView;

public partial class Default: System.Web.UI.MasterPage{
     private void FillTreeView{
           ExtendedTreeNode exTreeNode=new ExtendedTreeNode();
           exTreeNode.CreationDate=DateTime.Now;

           TreeView1.Nodes.Add(exTreeNode);
     }

   protected void TreeView1_SelectedNodeChanged(object sender, EventArgs
e){
       // It is throwing exception in this line.
        (ExtendedTreeNode)TreeView1.SelectedNode;
   }
}

>> Hi All,
>> I got a treeview object. I extended its TreeNodes to ExTreeNode and then
[quoted text clipped - 14 lines]
>
> Pete
Peter Duniho - 17 Dec 2007 18:46 GMT
> Ok, here the code.

That's not a complete sample of code.  Also, it appears that you're using  
the .NET web forms, which is not exactly the same as regular forms  
programming.  You should always be clear about the exact classes, if  
you're deviating from the standard Windows application environment.

If you do get around to posting complete code, hopefully someone will know  
how to use it.  I haven't used .NET for a web form application, and am not  
sure I'd even know how to run code posted for something like that.  :)

As far as debugging it goes, I would recommend you look at what the type  
actually is, as well as the data in the instance.  Obviously the type  
isn't what you expected it to be, so the first thing to do is to confirm  
whether the node instance you're trying to cast does in fact have any  
relation to the one you added.  There's nothing in the code you posted  
that would guarantee that it does, never mind that it is exactly the node  
you added.

If it is related to the one you added (e.g. it has some TreeNode field  
that's unique and identical...you'd of course want to set some TreeNode  
field so that you can test this), then the question becomes one of what's  
going on with the node when you add it or after.  Since I know this works  
for a regular TreeView (I've used the same technique myself), it could be  
something related to the web version of the classes you're using.  What  
that could be, I don't know since it's outside my experience.

Of course, it could just be a programming error on your part.  Without a  
complete sample of code (and instructions for how to use the program,  
since the code apparently depends on the user action, being in the  
SelectedNodeChanged event handler), there's no way to know.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.