This is a migrated thread and some comments may be shown as answers.

Bind to Business Object

11 Answers 143 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mohamed
Top achievements
Rank 1
Mohamed asked on 14 Aug 2008, 03:32 PM
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);}

}

11 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 15 Aug 2008, 07:49 AM
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.
0
Mohamed
Top achievements
Rank 1
answered on 17 Aug 2008, 02:31 PM
Thanks Simon ,
And Thanks to Ashraf for his effort
It works well
0
Wiebe
Top achievements
Rank 1
answered on 19 Aug 2008, 09:40 AM
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
0
Veselin Vasilev
Telerik team
answered on 19 Aug 2008, 12:42 PM
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.
0
Nick
Top achievements
Rank 1
answered on 21 Aug 2008, 08:55 AM
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
0
Veselin Vasilev
Telerik team
answered on 21 Aug 2008, 09:07 AM
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.
0
Nick
Top achievements
Rank 1
answered on 26 Aug 2008, 04:35 PM
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

0
Mohamed
Top achievements
Rank 1
answered on 27 Aug 2008, 07:07 AM
http://www.telerik.com/community/code-library/submission/b311D-mcmgt.aspx

Dear all, try the above. it works even with Microsoft TreeView
0
Nick
Top achievements
Rank 1
answered on 27 Aug 2008, 08:18 AM
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.

:(
0
Nick
Top achievements
Rank 1
answered on 28 Aug 2008, 02:23 PM
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

0
Phil C
Top achievements
Rank 2
answered on 02 Dec 2008, 03:57 PM
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.
Tags
TreeView
Asked by
Mohamed
Top achievements
Rank 1
Answers by
Simon
Telerik team
Mohamed
Top achievements
Rank 1
Wiebe
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Nick
Top achievements
Rank 1
Phil C
Top achievements
Rank 2
Share this question
or