Bind to Business Object

12 posts, 0 answers
  1. Mohamed
    Mohamed avatar
    3 posts
    Member since:
    Aug 2008

    Posted 14 Aug 2008 Link to this post

    Recently, Telerik annonced that its TreeView can bind to any custom collection object implementing IEnumerable.
    I am afraid this does not work properly (i.e. all nodes ar displayed as roots)
    Below is my object that I tested againest your control
    Kindly, investigate and advise if the problem source is my code or your component?

    public

    class MyObject

    {

    private int id; private int pId; private string name;

    public MyObject(int id, int pId, string name)

    {

    this.id = id; this.pId = pId; this.name = name;}

    public int ID { get { return id; } set { id=value;} }

    public int PId { get { return pId; } set { pId=value; } }

    public string Name { get { return name; } set { name = value; } }

    }

    /////////////////////////////////////////// Collection

    public

    class MyObjectCollection : IEnumerable, IEnumerator

    {

    private List<MyObject> obCollection = new List<MyObject>();

    int position = -1;

    public MyObjectCollection()

    {

    }

    public MyObjectCollection(List<MyObject> list)

    {

    obCollection = list;

    }

    public IEnumerator GetEnumerator()

    {

    return new MyObjectCollection(obCollection);

    }

    public MyObject this[int indexer]

    {

    get { return obCollection[indexer]; }

    set { obCollection[indexer] = value; }

    }

    public bool MoveNext()

    {

    position++;

    return (position < obCollection.Count);

    }

    public void Reset()

    {

    position = -1;

    }

    public object Current

    {

    get

    {

    try

    {

    return obCollection[position];}

    catch (IndexOutOfRangeException)

    {

    throw new InvalidOperationException();}

    }

    }

    public MyObjectCollection GetObjects()

    {

    return new MyObjectCollection(obCollection);}

    }

  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 15 Aug 2008 Link to this post

    Hello Mohamed,

    The support for hierarchical data binding to IEnumerable will be introduced with the forthcoming Service Pack 1 for RadControls for ASP.NET AJAX.

    Currently, the control does not support this functionality. You can see this Code Library Project which shows how hierarchical data binding can be achieved with the current version of the control.

    Greetings,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mohamed
    Mohamed avatar
    3 posts
    Member since:
    Aug 2008

    Posted 17 Aug 2008 Link to this post

    Thanks Simon ,
    And Thanks to Ashraf for his effort
    It works well
  5. Wiebe
    Wiebe avatar
    1 posts
    Member since:
    May 2008

    Posted 19 Aug 2008 Link to this post

    I have the same problem, and took me some time to find this.

    Maybe it's a good idea to mention it in the docs?

    Regards, Wiebe
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 19 Aug 2008 Link to this post

    Hello Wiebe,

    We will include the necessary information in our help once we release the service pack officially.


    Sincerely yours,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Nick
    Nick avatar
    86 posts
    Member since:
    Mar 2008

    Posted 21 Aug 2008 Link to this post

    Hi,

    Is there any ETA for this service pack?  I am currently developing an application where I am using LINQ to retrieve records from the database and would like to bind the resulting generic list (which implements IEnumerable) to the TreeView.

    The list currently binds ok, but all the items are shown in the root of the tree despite setting the DataFieldID and DataFieldParentID properties  :(

    Would this be corrected in the upcoming service pack?  I don't really want to code a different solution if this is coming soon.

      Private Sub PopulateTreeView() 
        Dim folders As List(Of Classes.Data.Entities.Folder) 
        folders = Classes.Application.GetFolders() 
        With rtvFolders 
          .DataSource = folders 
          .DataTextField = "FolderName" 
          .DataFieldID = "FolderID" 
          .DataFieldParentID = "ParentFolderID" 
          .DataValueField = "FolderID" 
          .DataBind() 
        End With 
        folders = Nothing 
      End Sub 
     

    Cheers,
    Nick
  8. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 Aug 2008 Link to this post

    Hello Nick,

    The service pack is scheduled for 26 August. You can check this code library:
    Updating Drag&Drop operations to Data Base through LinqDataSource

    Kind regards,
    Veskoni
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Nick
    Nick avatar
    86 posts
    Member since:
    Mar 2008

    Posted 26 Aug 2008 Link to this post

    Hi,

    I rather excitedly installed the latest patch today in the hope this would now render my treeview in a hierarchical manner, only to find that I have gone from all nodes in the root of  the treeview to no nodes at all.  :(

    Is there a specific DataFieldParentID value an item should have to indicate that it is a root item?  Currently my root items have a DataFieldParentID of 0.

    Thanks,
    Nick

  10. Mohamed
    Mohamed avatar
    3 posts
    Member since:
    Aug 2008

    Posted 27 Aug 2008 Link to this post

    http://www.telerik.com/community/code-library/submission/b311D-mcmgt.aspx

    Dear all, try the above. it works even with Microsoft TreeView
  11. Nick
    Nick avatar
    86 posts
    Member since:
    Mar 2008

    Posted 27 Aug 2008 Link to this post

    Hi Mohamed,

    I've looked at that sample before but you've kind of missed the point.

    The patch notes from yesterday's service pack state:

    What’s New

    1. findNodeByUrl  and findNodeByAbsoluteUrl  client side methods of RadTreeView.
    2. Initialiazation time improvement
    3. Hierarchical databinding to IEnumerable via the DataFieldID/DataFieldParentID properties
    4. Add DataBindings for the public properties of RadNode
    What I want to know is why not only has this not fixed the issue of binding custom objects in an IEnumerable list but has completely broken my treeview so nothing shows at all.

    :(
  12. Nick
    Nick avatar
    86 posts
    Member since:
    Mar 2008

    Posted 28 Aug 2008 Link to this post

    Ok, I found the cause of my issue. 

    Because the underlying database field for the parent id was marked as nullable, the LINQ class generated by the dbml file had the ParentID property as a Integer? (nullable) type rather than an Integer.  By changing the database field to Not Null and rebuilding the project the treeview now recognises the property as an integer and heirarchical binding is working as expected  :D

    Cheers,
    Nick

  13. Phil C
    Phil C avatar
    30 posts
    Member since:
    Sep 2012

    Posted 02 Dec 2008 Link to this post

    thank you thank you thank you, Nick. Even without LINQ, this class nullability was stopping my example binding code from working, using basic List and SQL IEnumerable collection. Couldn't work out why although suspicious, then read this and it sorted it! Cheers, Phil.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017