Persist Item Order

11 posts, 0 answers
  1. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 24 Feb 2010 Link to this post

    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.
  2. Bobi
    Admin
    Bobi avatar
    513 posts

    Posted 02 Mar 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Bobi
    Admin
    Bobi avatar
    513 posts

    Posted 02 Mar 2010 Link to this post

    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.
  5. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 02 Mar 2010 Link to this post

    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,

     

  6. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 09 Mar 2010 Link to this post

    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.
  7. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 23 Mar 2010 Link to this post

    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.



  8. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 25 Mar 2010 Link to this post

    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.
  9. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 25 Mar 2010 Link to this post

    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

  10. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 26 Mar 2010 Link to this post

    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.
  11. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 27 Mar 2010 Link to this post

    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

  12. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 30 Mar 2010 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready