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

SelectionChanged not triggering when SelectedItem not in View

8 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
NoRyb
Top achievements
Rank 1
NoRyb asked on 18 Mar 2010, 11:39 AM
Hello

In a situation I set the IsSelected-Property of some RowItems to true. The property "IsSelected" of "GridViewRow" is bound to the grid over DataBinding.

Now I wanted to make sure, that when I select an item from code, which is not visible at this time, it is scrolled into view. So I connected the SelectionChanged-Event of the GridView. The Problem is, the SelectionChanged-Event is only executed, if the item that I'm selecting is already in view! If it's way at the end of the list, the Event is never triggered and so I don't see which item gets selected. As soon as I scroll down and the item jumps into view, the SelectionChanged-Event is triggered.

Any suggestions how I can accomplish this? Things are very losely coupled so I can't just tell the GridView to select the item, it has to operate as soon as one of it's Items has the "IsSelected" property set.

Thanks
NoRyb

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 18 Mar 2010, 11:48 AM
Hi NoRyb,

You can use ScrollIntoView and SelectedItem instead - I've attached small example to illustrate you this.

Sincerely yours,
Vlad
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
NoRyb
Top achievements
Rank 1
answered on 18 Mar 2010, 11:55 AM
Hello Vlad

Thanks for the example but you use GridView1 in your Button. What you do in your Button I'm doing somewhere else and I use the MVVM-Pattern. I only have access to the ItemViewModels which have the property "IsSelected". This means I cannot use GridView1.XXX to do anything. Is nothing triggered in the GridView when the "IsSelected" property of a Row changes?

Thanks
0
Vlad
Telerik team
answered on 18 Mar 2010, 12:09 PM
Hi NoRyb,

I've attached a bit different example to illustrate you how to achieve your goal without depending on grid Name.

All the best,
Vlad
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
NoRyb
Top achievements
Rank 1
answered on 18 Mar 2010, 01:02 PM
Hello Vlad

Your example works thanks but what if I want to select multiple Items? I thought the only way was to use the IsSelected-Property of the GridViewRows.

Regards
0
Vlad
Telerik team
answered on 18 Mar 2010, 01:10 PM
Hello NoRyb,

You can add desired items in SelectedItems property in case of multiple selection.

Sincerely yours,
Vlad
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
NoRyb
Top achievements
Rank 1
answered on 18 Mar 2010, 01:20 PM
Hello Vlad

It isn't a DependencyProperty (so it can't be bound with DataBinding), I'll have the problem that I haven't got access to the GridView to set it manually.

Regards
0
Accepted
Vlad
Telerik team
answered on 18 Mar 2010, 02:03 PM
Hello NoRyb,

Here is again modified version with multiple selection.

Best wishes,
Vlad
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
NoRyb
Top achievements
Rank 1
answered on 18 Mar 2010, 03:49 PM
Hello Vlad

Thank you very much - it behaves like I want it to.

Regards
Tags
GridView
Asked by
NoRyb
Top achievements
Rank 1
Answers by
Vlad
Telerik team
NoRyb
Top achievements
Rank 1
Share this question
or