TreeView with custom HierarchicalDataSourceControl

Discussion in 'ASP .Net' started by Eamon Millman, Feb 3, 2006.

  1. 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
     
    Eamon Millman, Feb 3, 2006
    #1
    1. Advertising

  2. 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/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
    >
    >
    >
     
    =?Utf-8?B?RFdT?=, Feb 6, 2006
    #2
    1. Advertising

  3. Eamon Millman

    Kazarin Max Guest

    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
     
    Kazarin Max, Feb 18, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHltYm93?=
    Replies:
    2
    Views:
    24,490
    =?Utf-8?B?VHltYm93?=
    Jan 10, 2006
  2. =?Utf-8?B?RnJhbmNpcyBSZWVk?=

    HierarchicalDataSourceControl Class (FileSystemDataSource example)

    =?Utf-8?B?RnJhbmNpcyBSZWVk?=, Feb 28, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,735
    Fixme
    Jun 1, 2006
  3. Eamon Millman

    TreeView with custom HierarchicalDataSourceControl

    Eamon Millman, Feb 3, 2006, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    166
    Kazarin Max
    Feb 18, 2006
  4. Francis Reed

    HierarchicalDataSourceControl Class and System.StackOverflowExcept

    Francis Reed, Feb 28, 2006, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    152
    Joey Chömpff
    Apr 3, 2006
  5. Ionutz
    Replies:
    2
    Views:
    537
    Ionutz
    Oct 23, 2005
Loading...

Share This Page