Select a row from ViewModel

6 posts, 0 answers
  1. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 30 Sep 2010 Link to this post

    How do I select a spesific row from my ViewModel (we're using mvvm pattern and no codebehind)? I have tried several approaches with no luck. Tried to set SelectedItem, tried to set CurrentItem, IsSynchronizedWithCurrentItem true/false. Nothing seems to help. Debugging the ViewModel shows that the row is selected, but the Gui is not updated.
  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 01 Oct 2010 Link to this post

    Hi Roy Halvorsen,

    I have attached a sample project which demonstrates how you can bind RadGridView's SelectedItem to a ViewModel and change the SelectedItem from the ViewModel itself.

    Hope it helps.


    Kind regards,
    Milan
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Hui
    Hui avatar
    14 posts
    Member since:
    Jul 2016

    Posted 07 Jul in reply to Milan Link to this post

    Can we access the SelectedItem from ViewModel? The example used it from code behind.
  5. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 11 Jul Link to this post

    Hi Hui,

    In the attached demo application, indeed, the value of the SelectedItem property is changed on a button click in the code behind. Please, however, take a closer look, that the property is actually defined in the view model and the SelectedItem property of RadGridView is bound to it. You have a direct access to the SelectedItem property in the view model and can update it as per your requirements.

    Best Regards,
    Stefan X1
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Hui
    Hui avatar
    14 posts
    Member since:
    Jul 2016

    Posted 11 Jul in reply to Stefan X1 Link to this post

    I meant  Click="Button1_Click" is in code behind.

    I want to it in ViewModel to handle the property.

  7. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 14 Jul Link to this post

    Hello Hui,

    The way to go  is to use an ICommand. You may find the Basic MVVM and ICommand  Usage Example article useful on the matter.

    Hope this helps.

    Regards,
    Stefan X1
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready