ViewModel Setting bound property to null does not remove grid selection

6 posts, 0 answers
  1. StevenDale
    StevenDale avatar
    100 posts
    Member since:
    Apr 2007

    Posted 07 Aug 2009 Link to this post

    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,

     

  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 12 Aug 2009 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Laura
    Laura avatar
    5 posts
    Member since:
    Apr 2011

    Posted 01 Sep 2011 Link to this post

    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
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 01 Sep 2011 Link to this post

    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 >>

  6. Laura
    Laura avatar
    5 posts
    Member since:
    Apr 2011

    Posted 01 Sep 2011 Link to this post

    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
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 01 Sep 2011 Link to this post

    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 >>

Back to Top
UI for WPF is Visual Studio 2017 Ready