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

Selecting related items when a single item is selected

3 Answers 28 Views
TimeLine
This is a migrated thread and some comments may be shown as answers.
ben crinion
Top achievements
Rank 1
ben crinion asked on 15 Jul 2013, 10:21 AM
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

3 Answers, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 18 Jul 2013, 10:58 AM
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 >>
0
ben crinion
Top achievements
Rank 1
answered on 18 Jul 2013, 11:24 AM
Thanks, I didn't think of using "code behind" for this.

Is there a way of doing it with binding in an MVVM style?
0
Petar Kirov
Telerik team
answered on 22 Jul 2013, 02:58 PM
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 >>
Tags
TimeLine
Asked by
ben crinion
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
ben crinion
Top achievements
Rank 1
Share this question
or