Currently I have an EventToCommand that fires on the Sorted event of the RGV. I then call a function called GridSorted().
As I see it, there are two options...
1) Set my SelectedEmployee property (which the RGV SelectedItem is bound to)
2) "Select" the first item in the collection, as its sorted in the grid.
Any ideas on how to do either?
SS
7 Answers, 1 is accepted
I think I could not understand what the problem is.
What is stopping you from setting the SelectedItem property of RadGridView? Could you please explain?
Here is the article concerning selection. I believe that it can help. Please, take a look at it in case you have not.
Ross
the Telerik team
![](/forums/images/avatarimages/default.gif)
When the grid is bound to QueryableCollectionView every collection setting will be transfered to the grid automatically - you can safely do everything you want in your data layer and the grid will respect this immediately.
Best wishes,Vlad
the Telerik team
![](/forums/images/avatarimages/default.gif)
Sure, I understand the binding concepts quite well. What I don't understand is how to select not just the first item in a QueryableCollectionView, but the first item within the context of my sorting/filtering/paging. If I select the first item in the sourceCollection, it selects the first item in the initial query. What I want would be the first item in my newly sorted/filtered/paged list.... so whenever a user fires off any of these functions, the new dataset auto-selects the first item in this new set.
Does that make sense?
Thanks for your help,
SS
The first item in the QueryableCollectionView is in fact the first item within the context of your sorting/filtering/paging.
That is why it is called a View. It is a view over a source collection that applies your sorting/filtering/paging.
So imagine that your source collection is "1, 2, 3" and you have a filter that says "give me only the even numbers". The first item in the QueryableCollectionView will be 2. So this is the item that you are looking for.
I hope this makes sense.
Ross
the Telerik team
![](/forums/images/avatarimages/default.gif)
When the user fires off a filter, obviously my view changes, displaying the first 10 items in my filtered collection (RadDataPager.PageSize = 10). I'm using a dataform to show details of the items in my RadGridView, and I'd like to auto-select the 1st item in this collection. In Codebehind, this would be simple:
private
void
GV1_Sorted(
object
sender, Telerik.Windows.Controls.GridViewSortedEventArgs e)
{
if
(GV1.Items.Count > 0)
{
GV1.SelectedItem =
this
.GV1.Items[0];
}
}
That's obviously one way to do it. I'd like to avoid code behind, so I'm hoping to do this in my ViewModel. I'm successfully capturing the 'Sorted','Filtered' and 'SelectedCellsChanged' events. I have a property in my VM named 'SelectedEmployee' that's bound to my gridview & dataform. When somebody Sorts/Filters, I'd like to set my SelectedEmployee to the 1st item in my newly filtered/sorted list. How do I do this? It would be something like SelectedEmployee = (Model.Employee)EmployeeQCV.Items[0]. Obviously that line doesn't work, but I don't know what to put in place of the (Model.Employee)EmployeeQCV.Items[0].
Thanks for your help.
Only lists have indexers, i.e. this.myList[0];
To learn how to select the first element of an IEnumerable, please search for the following phrase in Google:
"how do I select the first element of an IEnumerable"
The first search result that appears explains everything. The other results are also very helpful.
Personally, I would use the First() LINQ method, since I find it most convenient. To see all other Enumerable methods, please take a look at this article.
To learn what is the difference between an array, a list, and an IEnumerable, please take a look at this article.
I hope this helps.
Ross
the Telerik team