473,473 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

TreeView with custom HierarchicalDataSourceControl

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/s...cecontrol.aspx

http://msdn2.microsoft.com/library/s...debinding.aspx
http://msdn2.microsoft.com/library/s...ndcontrol.aspx
Feb 3 '06 #1
2 3800
DWS
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.
"Eamon Millman" wrote:
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/s...cecontrol.aspx

http://msdn2.microsoft.com/library/s...debinding.aspx
http://msdn2.microsoft.com/library/s...ndcontrol.aspx

Feb 6 '06 #2
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
Feb 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve | last post by:
I have created a transparent custom drawn treeview in c#(using lots of native code as well) that has a bitmap for its background. As well as that, I have created a custom highlight that is a...
8
by: JJBean | last post by:
Hi All, How do I create a custom paint treeview control or an owner drawn treeview control ? Any tutorials on this anywhere? Thanks, JJBean
0
by: rh | last post by:
Hi, I have a WinForm with a TreeView and a custom scrollbar control that is positioned over (hides) the TreeView's own default ScrollBar. I use SetScrollInfo to update the TreeView's default...
7
by: vsiat | last post by:
I am trying to create a treeview out of a database table with the typical structure ID, NAME, PARENTID, TYPE, EXTRA_INFO, where is linked to the . What I want to achieve is create a tree made...
2
by: kevin | last post by:
I would like to remember the state of the nodes after the treeview gets disposed, but not necessarily after the app terminates so I don't need a disk file. I was thinking about using the tag...
2
by: Loopsludge | last post by:
Using ASP.NET 2005/C# flavor, I need to dynamically populate a TreeView control from the results of a SQL Server 2005 query. Clicking on the end leaf of the tree will need to yield some details...
0
by: apenly | last post by:
Hi all- I'm trying to Render a TreeView in a custom control, but I'm receiving a NullReferenceException at runtime. If I put the TreeView on the page it works fine, but as soon as I try to...
0
by: noneya22 | last post by:
I want to use a TreeView control as a one-level, vertical navigation menu. I'm using this control currently with a SiteMapDataSource and .sitemap file. I've written code that associates an image...
18
by: =?Utf-8?B?TGkgV2VuZw==?= | last post by:
Hi, Is there a way for TreeView to have multiple selections? But I am not talking about its checked boxes. I want a way similar to ListView with MultiSelect = True. So I can use or key and...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.