TreeView with custom HierarchicalDataSourceControl

E

Eamon Millman

Greetings,



I'm fairly new to the new ASP.NET 2.0 controls and I'm trying to get the
TreeView control to display some non-xml/sitemap data I want to have in a
tree format. To accomplish this I have followed the sample code provided on
the MSDN website for writing a custom HierarchicalDataSourceControl,
HierarchicalDataSourceView, IHierarchicalEnumerable, and IHierarchyData
implementations (their FileSystem example).



Now the TreeView renders the proper nodes, even places the correct field
values for Text and ToolTip that I set in the Databindings. However, I
cannot seem to access the IHierarchyData object that was used to get all
this data. I've examined the TreeView1.SelectedNode when I handle the
TreeView.SelectedNodeChanged event but I can't see where the data is. I'm
assuming it should be accessible as the SelectedNode.DataItem, but this
value is always null.



Does anyone have suggestions for me to look at? I've looked up the
HierarchicalDataBoundControl and will probably pursue it as a possible
solution for the time being. If you want a look at the code for all this let
me know and I'll get it to you.





Eamon Millman



The MSDN articles I've worked from are:

http://msdn2.microsoft.com/library/system.web.ui.hierarchicaldatasourcecontrol.aspx

http://msdn2.microsoft.com/library/system.web.ui.webcontrols.treenodebinding.aspx
http://msdn2.microsoft.com/library/system.web.ui.webcontrols.hierarchicaldataboundcontrol.aspx
 
G

Guest

Eamon,
Hello,
You are definately on the right track! The dataitem is only available a
binding time, I was bummed on that too a while back. I don't know of any
examples but look at the fileinfo example. The author is returning a
fileinfo object. If you need something extra in your tree you create a
strongly typed object and return it instead of the fileinfo object. You then
access the properties of your strongly typed object in the treeview databound
event. Every where in the fileinfo example a fileinfo object is created you
would be creating your new strongly typed object. For an employee structure
all you need is the employeeid or better yet an employee class. The new
constructor for your strongly typed object just has to populate the
properties of your strongly typed class based on the input employee. A
district manager would be the parent of all the managers in their disctrict
and a regular manager would be the parent of all the employees at their
location.
method getchildren
The get children method returns an array of the strongly typed object.
for each employee in employee.directs
children.add( New FileSystemHierarchyData(employee))
next

if the employee is at the bottom of the food chain like me
haschildren (bool) method
if employee.id = 'DWS" then return false
It just has to work with your data.

Public Class FileSystemHierarchyData
Implements IHierarchyData

Public Sub New(employee as object)
me.employee = obj
End Sub 'New
private employee as DWS.Co.employee

Public Overridable ReadOnly Property Item() As Object _
Implements IHierarchyData.Item
Get
Return me.employee
End Get
End Property


Good Luck Millman
DWS

Reply to group or thread if you need more help.
 
K

Kazarin Max

I have the same problem with DataItem property. It has null value. How do
solve this problem?
I spend two days but have not found decision
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top