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
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.
And Thanks to Ashraf for his effort
It works well
Maybe it's a good idea to mention it in the docs?
Regards, 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.
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
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.
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
Dear all, try the above. it works even with Microsoft TreeView
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
- findNodeByUrl and findNodeByAbsoluteUrl client side methods of RadTreeView.
- Initialiazation time improvement
- Hierarchical databinding to IEnumerable via the DataFieldID/DataFieldParentID properties
- Add DataBindings for the public properties of RadNode
:(
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