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

ViewModel Setting bound property to null does not remove grid selection

5 Answers 120 Views
GridView
This is a migrated thread and some comments may be shown as answers.
StevenDale
Top achievements
Rank 2
StevenDale asked on 07 Aug 2009, 08:15 PM
I have a RadGrid that has its SelectedItem property bound to a property in my ViewModel. In my ViewModel, if I set the item that is bound to the selected item equal to null I would expect that the selection would be removed from the RadGrid, but it does not.
XAML:
<telerik:RadGridView Grid.ColumnSpan="2" SelectedItem="{Binding Path=WorkingMedicationOrder.DrugDosage_, Mode=TwoWay}" ItemsSource="{Binding DrugDosages}" Grid.Row="5" AutoGenerateColumns="False" ShowGroupPanel="False"
In my ViewModel I do the following expecting the SelectedItem in the RadGrid to be removed.

WorkingMedicationOrder.DrugDosage_ =

null;

Thanks,

 

5 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 12 Aug 2009, 09:53 AM
Hi Billy Jacobs,

I have prepared a small sample project trying to reproduce what you have described but I could not. My project uses the latest internal build and when I set null to the property from the view model the grid selection is cleared.

Can you give it a spin on your end and see whether it will work. Another option is to modify it in a way to reproduce the issue you are faced with and send it back.

Sincerely yours,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Laura
Top achievements
Rank 1
answered on 01 Sep 2011, 05:32 AM
My issue is similar to this. SelectedItem of my RadGridView is bound to a property in my viewModel. When I change that property to a NEW object, SelectedItem is not updated. To reproduce, modify your attached project on Window1.xaml.cs like this:
private void OnClearSelected(object sender, RoutedEventArgs e)<br>{<br>            this.viewModel.SelectedClub = new Club("LAURA", DateTime.Now, 5);<br>}


Thanks,
LauraH
0
Rossen Hristov
Telerik team
answered on 01 Sep 2011, 12:13 PM
Hi Laura,

Pardon me if I have misunderstood your question, but if I understand this correctly, you are creating a brand new object and then assigning it as the SelectedItem of RadGridView. Since you have just created this brand new object, it is not part of the source collection of RadGridView in any way. RadGridView only shows items that are part of its source collection.

How should RadGridView select an item, which is not part of its source collection and is not displayed in RadGridView in any way? Which row should RadGridView select as a result of this source code you have provided? 

What happens if you do the same thing with a plain stock ListBox?

Could you please elaborate what is the behaviour that you expect given the source code that you provided? 

Kind regards,
Ross
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Laura
Top achievements
Rank 1
answered on 01 Sep 2011, 03:43 PM
Thank you so much for the quick response. You're right; I guess I was wrongly expecting for the item in the list to be updated... the whole reason I started that route was because on selection, I retrieve extra information about that record to show in a detailed view. So I wanted to replace the item in the list with the new one, but doing it directly in the list was triggering my selectionChanged code again which would make the call again for more data and continue in that loop... But now I'm signaling to know whether I triggered the selectionChanged by replacing the item in the list or not.

Thanks!
LauraH
0
Rossen Hristov
Telerik team
answered on 01 Sep 2011, 04:09 PM
Hi Laura,

Here you can learn more about selection. Basically, selection works just like any other possible selection out there.

Let us know if you have any particular questions.

All the best,
Ross
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
StevenDale
Top achievements
Rank 2
Answers by
Rossen Hristov
Telerik team
Laura
Top achievements
Rank 1
Share this question
or