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

Persist Item Order

10 Answers 110 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
heavywoody
Top achievements
Rank 1
heavywoody asked on 24 Feb 2010, 03:06 PM
I am wondering if this is possible.  I am binding a self-referencing table to a treeview.  One of the columns is SortOrder.  The users have the ability of moving the items in the treeview up and down within a parent node, or moved to another node and up and down in that one.  When the user has made all the moves they want and click save, what has to be saved then is what order the nodes are in under each node.  So for example it should be saved like:

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

Sort by
0
Bobi
Telerik team
answered on 02 Mar 2010, 07:44 AM
Hello Christian Loepp,

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.
0
Bobi
Telerik team
answered on 02 Mar 2010, 07:53 AM
Hi Christian Loepp,

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.
0
heavywoody
Top achievements
Rank 1
answered on 02 Mar 2010, 10:40 PM
Thanks for putting together that excellent example together for me.  You guys have the best support by far!

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,

 

0
Tihomir Petkov
Telerik team
answered on 09 Mar 2010, 12:38 PM
Hello Christian,

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.
0
heavywoody
Top achievements
Rank 1
answered on 23 Mar 2010, 11:08 PM
It took me a bit to get back to this.  Ok, so I mocked up mine like yours.  I actually had to extend my Linq To SQL class in order to support your methods on your DataItem like SetParent.   My data shows fine now.  But I am at a loss as to how the SortOrder field I have in my WorkFlow object is updated to the index it is current at under a parent?
 
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.



0
Tihomir Petkov
Telerik team
answered on 25 Mar 2010, 02:39 PM
Hello Christian,

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.
0
heavywoody
Top achievements
Rank 1
answered on 25 Mar 2010, 02:54 PM

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

0
Tihomir Petkov
Telerik team
answered on 26 Mar 2010, 02:44 PM
Hello Christian,

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.
0
heavywoody
Top achievements
Rank 1
answered on 27 Mar 2010, 05:27 AM
Hi, I unzipped the project but couldn't get it to compile.  So I am unclear of how to use it.

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

0
Tihomir Petkov
Telerik team
answered on 30 Mar 2010, 01:41 PM
Hi Christian,

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.
Tags
TreeView
Asked by
heavywoody
Top achievements
Rank 1
Answers by
Bobi
Telerik team
heavywoody
Top achievements
Rank 1
Tihomir Petkov
Telerik team
Share this question
or