NFL
- Name: AFC East SortOrder:1
-- Name: Patriots SortOrder:1
-- Name: Jets SortOrder:2
- Name: AFC South SortOrder: 2
-- Name: Colts SortOrder: 1
-- Name: Titans SortOrder: 2
I was thinking of looping through each node and checking maybe the child index and saving that. Not sure if that would work. Ideally, I would love to be able to Bind the SortOrder to like the child index so it would automatically change if it was moved.
10 Answers, 1 is accepted
More information how to use RadTreeView with self-referencing data and a sample project you can find here:
http://blogs.telerik.com/valerihristov/posts/09-08-26/self-reference_hierarchy_with_telerik_treeview_for_silverlight.aspx
Regards,
Bobi
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Please find attached the WPF version of the sample project.
Kind regards,
Bobi
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I have a question about the self referencing example, though, as I ran into a problem. I am using a linq query to populate the tree, which uses my entity called WorkFlow. Since I want to bind the index and parent to each node so that wherever it was moved, that would be updated, I assumed I could not wrap it in a collection like you have. So my converter is a bit different:
public
object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// We are binding an item
WorkFlow item = value as WorkFlow;
if (item != null)
{
var items = from t in DataAccess.ctx.WorkFlows
where t.ParentItemID == item.ItemID
orderby t.SortOrder ascending
select t;
ObservableCollection<WorkFlow> itemcoll = new ObservableCollection<WorkFlow>(items.ToList());
return itemcoll;
}
else
{
//// We are binding the treeview
var treeitems = from t in DataAccess.ctx.WorkFlows
where t.ParentItemID == null
orderby t.SortOrder ascending
select t;
ObservableCollection<WorkFlow> treecoll = new ObservableCollection<WorkFlow>(treeitems.ToList());
return treecoll;
}
}
The problem I run into is that if I try to loop through all the data items in the tree, it only recognizes the top nodes. My guess is since the subitems are using a new query, they have a different data context and therefore are not found. So I cannot do what you have here using my converter:
foreach
(DataItem item in rtv.Items)
{
RadTreeViewItem tvi = rtv.ContainerFromItemRecursive(item);
if (tvi.CheckState == ToggleState.On)
{
tvi.IsExpanded =
true;
tvi.IsSelected =
true;
}
}
So, I am just unsure of how to make this work if I cannot create an object like what you have and it is against a LINQ entity. What I wanted is that as soon as I move an item, or create a new item, as soon as it is given a location in the tree, the SortOrder and ParentItemID is updated.
My table's properties are this. So ParentID should always be the parent node and SortOrder should be the index within the parent subitems.
CREATE
TABLE [dbo].[WorkFlow](
[ItemID] [uniqueidentifier]
ROWGUIDCOL NOT NULL,
[ParentItemID] [uniqueidentifier]
NULL,
[Name] [varchar]
(50) NULL,
[TableName] [varchar]
(50) NULL,
[FullPath] [varchar]
(50) NULL,
[SortOrder] [int]
NULL,
[SheetID] [uniqueidentifier]
NULL,
I apologize for the delayed response. You will have to wrap your raw data in a ParentAwareCollection, similar to what is done in the sample project. Simply bind your TreeView to the raw flat collection of WorkFlow objects and the converter will take care of the hierarchy (you have to substitue the DataItem for the WorkFlow type).
Let me know if this helps.
Greetings,
Tihomir Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I don't use integers for my ID, but instead Guids for both the ItemID and the ParentItemID. So I can't just set the ID to be what the index is. I have a SortOrder field which needs to persist the Index.
I tried to combine this post with another of Drag, Drap, IndexOf. The problem is, using
ContainerFromItemRecursive doesn't work because beyond the tree root items, nothing else shows. My guess is it is because on the Converter, it builds the childnodes on the fly and they have a different DataContext.
I am sending you an improved HierarchyConverter project which is better than the first and which is a better implementation for your scenario. Using it, you will be able to simply call the ReverseHierarchyConverter.GetOrderedItemsSource() method when you want to persist your data and, based on the order of the items in the returned collection, set the SortOrder property of your business objects. Please take a look at the project and let me know if you have any difficulties.
Best wishes,
Tihomir Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tihomir,
Thank you so much for your always quick response. I have downloaded the sample twice you attached and I don't see the difference or a new method to called ReverseHierarchyConverter.GetOrderedItemsSource() . Perhaps I missed something? Or is it possible you accidently uploaded the wrong one?
Sincerely,
C
My apologies, it seems I have mistakenly attached the wrong file. I am re-attaching the project to this post. I hope everything is fine now.
Best wishes,
Tihomir Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I thought what might make it easier is that I created a stripped down version of my project that has the DB (SQL express), LINQ to SQL, and then the treeview. Using the items you gave me before I can populate it. I just am unsure how to save the index to the SortOrder. You can get it at http://www.geostratsys.org/TreeViewForTelerik.zip
I updated your project to use the newer hierarchy converter and preserve the order of the items in the SortOrder property. Please take a look at the updated project and let me know if it will work for you.
All the best,
Tihomir Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.