How to select the first Row in RadGrid

14 posts, 1 answers
  1. Srini
    Srini avatar
    41 posts
    Member since:
    Jul 2009

    Posted 03 Sep 2009 Link to this post

    Hi All

    How to select the first row in radGridView..


    I used this but it is showing run time exception.
                            rgvCustSearch.CurrentRecord.IsSelected = true;
  2. Answer
    Inquisitor Jax
    Inquisitor Jax avatar
    26 posts
    Member since:
    Sep 2009

    Posted 03 Sep 2009 Link to this post

    try

    if (grid.Records.count > 0)
    {
       grid.Records[0].IsSelected = true;
    }
  3. DevCraft banner
  4. Srini
    Srini avatar
    41 posts
    Member since:
    Jul 2009

    Posted 03 Sep 2009 Link to this post

    Thank You Jax,

    I got it.
  5. Michał Polak
    Michał Polak avatar
    5 posts
    Member since:
    Jan 2010

    Posted 17 Feb 2010 Link to this post

    Current version of RadGridView doesn't have Records collection, how can I select first row now?
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Feb 2010 Link to this post

    Hi,

    You can assign SelectedItem to desired object. You can check our online demos for more info about latest techniques.

    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.
  7. Michał Polak
    Michał Polak avatar
    5 posts
    Member since:
    Jan 2010

    Posted 18 Feb 2010 Link to this post

    Yes but how can I identify which object is first i grid? I'm binding ItemsSource to ICollection, but taking first object from ICollection doesn't work, the order is different after sorting the grid.
  8. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 18 Feb 2010 Link to this post

    Hi Michał Polak,

    You can use the Items property of RadGridView, where all items are in the order they appear in the grid. Getting the first item is as easy as "var firstItem = this.myGrid.Items[0]".

    Hope this helps.


    Best wishes,
    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.
  9. Michał Polak
    Michał Polak avatar
    5 posts
    Member since:
    Jan 2010

    Posted 18 Feb 2010 Link to this post

    OMG so simple, I must have been too tired yesterday.
    Thank you for help :)

    Best regards,
    Michał
  10. Levi
    Levi avatar
    14 posts
    Member since:
    Sep 2011

    Posted 16 Sep 2011 Link to this post

    It might be asking too much, but would it be possible for the Client-Side selected event to trigger (on page load) when a row is selected in the code behind??
  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Sep 2011 Link to this post

    Hello Levi,

    Would you clarify a bit what are your exact requirements ?
    Generally, if you set the SelectedItem in code-behind:

    this.clubsGrid.SelectedItem = this.clubsGrid.Items[0];

    SelectionChanged event will be fired.
    What is the behavior that you want to achieve ? 
     

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  12. Bryce
    Bryce avatar
    32 posts
    Member since:
    Aug 2010

    Posted 14 Dec 2011 Link to this post

    Hi Maya,

    Since I am binding my SelectedItem to something in my ViewModel, I get an exception when I do it the way you demonstrated. I have a sortdescriptor on my grid and in my ViewModel when I do SelectItem.FirstOrDefault(), I get the first item selected before the sortdescriptor sorts the grid. Is there a way around this?

    Thanks,
    Bryce
  13. Tyree
    Tyree avatar
    105 posts
    Member since:
    Dec 2006

    Posted 15 Dec 2011 Link to this post

    For managing in a VM I find the easiest approach is you use a CollectionViewSource. Then you can manage selection, sorting, etc right from the VM and no monkeying with UI events and bindings.

    To try it take your current collection and make it an ObservableCollection (if its not already). Create a public CollectionViewSource and sets its .Source to your ObservableCollection. Now bind your grids .ItemSource to the CollectionViewSource.View. Now in your VM you can do CollectionViewSource.View.CurrentItem to see whats selected, or if you set it you can make it select something else.
  14. Jose
    Jose avatar
    8 posts
    Member since:
    Feb 2012

    Posted 12 Mar 2012 Link to this post

    Hi,
    I had the same problem.
    You can try this:

    this.clubsGrid.BeginInvoke( () =>
         this.clubsGrid.SelectedItem = this.clubsGrid.Items[0]);

    Works with me.
    Regards,
    Jose
  15. Walter
    Walter avatar
    1 posts
    Member since:
    Sep 2012
Back to Top
DevCraft banner