Selecting related items when a single item is selected

4 posts, 0 answers
  1. ben crinion
    ben crinion avatar
    8 posts
    Member since:
    Nov 2009

    Posted 15 Jul 2013 Link to this post

    Hi

    My application tracks "items", when they arrive they're placed into an area and my timeline shows a span from when they arrive to when they leave.

    I group my timeline objects using the AreaName property. An item can be moved between areas, when an item is moved the span stops in the first area and a new span is created in the new area.

    What I want to do is highlight the whole history of the item when any of the sectors is selected. I.e. select the spans in areas "a", "b" and "c" for item "x" in the different area groups when the item is selected in area "a"

    I hope this makes sense.
    Thanks
    Ben

  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 18 Jul 2013 Link to this post

    Hi Ben,

    As far as understand you, when a new item arrives, say X, it is placed in a group depending on its AreaName property. Then when it moves to area b, you are creating a new item Xb and you are adding it to the Timeline ItemsSource. And when X moves again you create Xc and again add it to ItemsSource.

    In order to be able select the item X across all groups (areas in your scenario), you need to know that Xa, Xb and Xc all represent the same item X, but in different groups.
    You can for example have a property named Origin which holds a reference to the original object X. Given that, you should be able to use the SelectionChanged event like this:
    bool isSelectionChanging = false;
     
    void Timeline_SelectionChanged(object sender, SelectionChangeEventArgs e)
    {
        if (isSelectionChanging)
            return;
     
        isSelectionChanging = true;
     
        if (e.AddedItems.Count > 0)
        {
            var origin = (e.AddedItems.Last() as MyItem).Origin;
     
            var allItemsWithTheSameOrigin = (timeline.ItemsSource as List<MyItem>)
                .Where(p => p.Origin == origin);
     
            foreach (var item in allItemsWithTheSameOrigin)
            {
                if (!timeline.SelectedItems.Contains(item))
                    timeline.SelectedItems.Add(item);
            }
        }
     
        isSelectionChanging = false;
    }

    I hope this helps.
     
    Regards,
    Petar Kirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. ben crinion
    ben crinion avatar
    8 posts
    Member since:
    Nov 2009

    Posted 18 Jul 2013 Link to this post

    Thanks, I didn't think of using "code behind" for this.

    Is there a way of doing it with binding in an MVVM style?
  5. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 22 Jul 2013 Link to this post

    Hi Ben,

    Perhaps a more suitable (MVVM-friendly) solution for your project would be to create a Behavior class which will synchronize the RadTimeline.SelectedItems property with a similar property in your ViewModel. On this link you will find a solution to this problem for a ListBox, but the same approach can be applied to RadTimeline with minimal changes to the code.
     

    Regards,
    Petar Kirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top