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

How to select the first Row in RadGrid

13 Answers 1016 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Srini
Top achievements
Rank 1
Srini asked on 03 Sep 2009, 01:44 PM
Hi All

How to select the first row in radGridView..


I used this but it is showing run time exception.
                        rgvCustSearch.CurrentRecord.IsSelected = true;

13 Answers, 1 is accepted

Sort by
0
Accepted
Inquisitor Jax
Top achievements
Rank 1
answered on 03 Sep 2009, 02:27 PM
try

if (grid.Records.count > 0)
{
   grid.Records[0].IsSelected = true;
}
0
Srini
Top achievements
Rank 1
answered on 03 Sep 2009, 02:59 PM
Thank You Jax,

I got it.
0
Michał Polak
Top achievements
Rank 1
answered on 17 Feb 2010, 07:30 PM
Current version of RadGridView doesn't have Records collection, how can I select first row now?
0
Vlad
Telerik team
answered on 18 Feb 2010, 06:50 AM
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.
0
Michał Polak
Top achievements
Rank 1
answered on 18 Feb 2010, 01:16 PM
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.
0
Milan
Telerik team
answered on 18 Feb 2010, 01:20 PM
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.
0
Michał Polak
Top achievements
Rank 1
answered on 18 Feb 2010, 01:33 PM
OMG so simple, I must have been too tired yesterday.
Thank you for help :)

Best regards,
Michał
0
Levi
Top achievements
Rank 1
answered on 16 Sep 2011, 05:57 PM
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??
0
Maya
Telerik team
answered on 17 Sep 2011, 02:46 PM
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 >>

0
Bryce
Top achievements
Rank 1
answered on 14 Dec 2011, 11:56 PM
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
0
Tyree
Top achievements
Rank 2
answered on 15 Dec 2011, 02:24 PM
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.
0
Jose
Top achievements
Rank 1
answered on 12 Mar 2012, 03:15 PM
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
0
Walter
Top achievements
Rank 1
answered on 06 Dec 2012, 04:10 PM
Tags
GridView
Asked by
Srini
Top achievements
Rank 1
Answers by
Inquisitor Jax
Top achievements
Rank 1
Srini
Top achievements
Rank 1
Michał Polak
Top achievements
Rank 1
Vlad
Telerik team
Milan
Telerik team
Levi
Top achievements
Rank 1
Maya
Telerik team
Bryce
Top achievements
Rank 1
Tyree
Top achievements
Rank 2
Jose
Top achievements
Rank 1
Walter
Top achievements
Rank 1
Share this question
or