How to make the 1st row be a default SelectedItem in MVVM or in XAML property?

2 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    172 posts
    Member since:
    Jan 2010

    Posted 12 Nov 2014 Link to this post

    I was hoping there would be a easy way to automatically set the first row as "selected" using SelectedIndex="1" in my XAML ... but I can't see to find such a method.   The only thing I found was considerable code to setup a behavior here:

    I really don't want to write that much code for such a simple task ... all I really want to do is set the first row as selected once data source is loaded/set (which should trigger a selectionchanged which my MVVM code will pickup using Interactivity DLLs.

    In a windows forms app, this takes 1 short line of code ... in SL this same task seems to take about 300 lines of code?

    I'm hoping I'm wrong and there is an easy MVVM way or even just a property in my XAML for the GridView.

    Cheers, Rob.
  2. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 14 Nov 2014 Link to this post

    Hello Rob,

    The case is that initially there are still not items loaded, consequently the SelectedItem cannot be connected with the GridViewRow corresponding to the particular item. You could subscribe for the DataLoaded event of RadGridView and select the desired item as soon as the data in the control is loaded.

    You will be able to assign it once it is actually loaded.

    For example, you can assure the item is already available with the following code:

    void RadGridView1_DataLoaded(object sender, System.EventArgs e)
        var item4 = RadGridView1.Items[3];
        if (RadGridView1.Items.Contains(item4))
            RadGridView1.SelectedItem = item4;

    Let me know how this works for you.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. DevCraft R3 2016 release webinar banner
Back to Top