Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Custom TreeNode for asp.net 2.0 treeview control

Reply
Thread Tools

Custom TreeNode for asp.net 2.0 treeview control

 
 
Rickey Whitworth
Guest
Posts: n/a
 
      01-18-2006
I want to display a treeview control that is tied to a sql database.

The child nodes will be of different types, meaning they will have different
attributes and different tables

-Root
--Service1 (select * from services) value = serviceID = 1
---Database1 (select * from databases where serviceID = ?)
---Website1 (select * from websites where serviceID = ?)

When I click on a node, I want to display attributes of that node in the
right pane. I have handled this before in a windows application by creating
a custom treeNode that has an extra field for type (service, database or
website).

Here is my custom tree node and my enumeration for type

Public Enum NodeType
Service
Application
Database
Website
End Enum

Public Class CustomTreeNode
Inherits TreeNode

Private _ntype As NodeType

Public Property NType() As NodeType
Get
Return _ntype
End Get
Set(ByVal value As NodeType)
_ntype = value
End Set
End Property

Public Sub New(ByVal text As String, ByVal value As String, ByVal
nType As NodeType)
MyBase.New(text, value)
_ntype = nType
End Sub

Public Sub New()
MyBase.New()
End Sub
End Class

And I get an error in this function

Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.TreeNodeEventArgs) Handles
TreeView1.TreeNodePopulate
If e.Node.ChildNodes.Count = 0 Then
Select Case e.Node.Depth
Case 0
FillAuthors(e.Node)
Case 1
FillTitlesForAuthors(e.Node)
Case 2
FillDatabase(e.Node)
End Select
End If
End Sub


Unable to cast object of type 'System.Web.UI.WebControls.TreeNode' to type
'CustomTreeNode'

I'm not really sure how to make this work. I can give more code samples as
needed, but I just need someone who can point me in the right direction. Is
there some other function or property of the treenode I need to override, do
I need to create a custom treeview control and override some event in it?


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-19-2006
Hi Rickey,

Welcome.
As for the ASP.NET 2.0 TreeView control, we can create custom control to
derived from it , also define our custom TreeNode class.... Also,
currently I'm also discussing such similiar question with other guy in the
newsgroup, here is the web link to the thread:

#Inheriting from the TreeNode class
http://groups.google.com/group/micro...rk.aspnet.webc
ontrols/browse_thread/thread/b0f3459b35105353/df2f38d4c2b2dc20?lnk=st&q=Inhe
riting+from+the+TreeNode+class&rnum=1&hl=en#df2f38 d4c2b2dc20

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Rickey Whitworth" <(E-Mail Removed)>
| Subject: Custom TreeNode for asp.net 2.0 treeview control
| Date: Wed, 18 Jan 2006 10:48:31 -0600
| Lines: 76
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <#(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontro ls
| NNTP-Posting-Host: 66.182.150.119
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontro ls:32567
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
|
| I want to display a treeview control that is tied to a sql database.
|
| The child nodes will be of different types, meaning they will have
different
| attributes and different tables
|
| -Root
| --Service1 (select * from services) value = serviceID = 1
| ---Database1 (select * from databases where serviceID = ?)
| ---Website1 (select * from websites where serviceID = ?)
|
| When I click on a node, I want to display attributes of that node in the
| right pane. I have handled this before in a windows application by
creating
| a custom treeNode that has an extra field for type (service, database or
| website).
|
| Here is my custom tree node and my enumeration for type
|
| Public Enum NodeType
| Service
| Application
| Database
| Website
| End Enum
|
| Public Class CustomTreeNode
| Inherits TreeNode
|
| Private _ntype As NodeType
|
| Public Property NType() As NodeType
| Get
| Return _ntype
| End Get
| Set(ByVal value As NodeType)
| _ntype = value
| End Set
| End Property
|
| Public Sub New(ByVal text As String, ByVal value As String, ByVal
| nType As NodeType)
| MyBase.New(text, value)
| _ntype = nType
| End Sub
|
| Public Sub New()
| MyBase.New()
| End Sub
| End Class
|
| And I get an error in this function
|
| Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e
As
| System.Web.UI.WebControls.TreeNodeEventArgs) Handles
| TreeView1.TreeNodePopulate
| If e.Node.ChildNodes.Count = 0 Then
| Select Case e.Node.Depth
| Case 0
| FillAuthors(e.Node)
| Case 1
| FillTitlesForAuthors(e.Node)
| Case 2
| FillDatabase(e.Node)
| End Select
| End If
| End Sub
|
|
| Unable to cast object of type 'System.Web.UI.WebControls.TreeNode' to
type
| 'CustomTreeNode'
|
| I'm not really sure how to make this work. I can give more code samples
as
| needed, but I just need someone who can point me in the right direction.
Is
| there some other function or property of the treenode I need to override,
do
| I need to create a custom treeview control and override some event in it?
|
|
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to access the Page from a TreeNode (treeview 's element) : addinga context menu to a treeview abargaddon ASP .Net Building Controls 0 01-17-2008 11:05 AM
Add a control to a treenode. TreeView Jerry C ASP .Net Web Controls 2 07-17-2006 05:55 AM
what is equivalent of vb.net treenode.nextnode property in asp.net webcontrols.treenode tanya foster ASP .Net 3 05-18-2006 05:58 PM
Treeview control. No selected treenode wanted jason.hau@gmail.com ASP .Net 0 01-23-2006 01:55 PM
Issue with a custom TreeView derived from the TreeView control Ionutz ASP .Net Web Controls 2 10-23-2005 03:23 PM



Advertisments