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

How to row current based on underlying bound data source row

4 Answers 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
BRiddle
Top achievements
Rank 1
BRiddle asked on 15 Aug 2011, 08:06 PM
I am new to the WPF RadGridView and have a simple question.   I need to implement a search which looks at all columns of all rows in a bound, virtualized,  WPF RadDataGrid.   After discovering that the "ChildrenOfType<GridViewRow>()" function only returns a list of visible rows,  I searched this forum for an appropriate technique.  

I say one technique involving the RadGridView's "Records" property.   The current RadGridView does not have a "Records" property.

I also saw a couple of hits recommending searching the underlying bound data source instead of searching the actual grid rows.   That's easy enough.

But once I find the desired row in the underlying bound data (in this case an ObservableCollection<T>), how do I determine the matching grid row - and move it into the visible set on the user's screen - in a way that still works if the grid is sorted in a different order from the underlying bound data source?  

Thanks!
-Bob

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 16 Aug 2011, 06:53 AM
Hi Bob,

Indeed, the ParentOfType<T> and ChildrenOfType<T> extension methods will return only the visible items as the virtualization of the RadGridView is turned on by default.  This means that only those visible elements are created and available. On scrolling they will be recycled and reused. That is why the recommended approach is to work with the underlying data item.
Considering scrolling to a particular one, you may benefit from the ScrollIntoView/ ScrollIntoViewAsync methods. It will work despite the sorting state of the grid.
Let me know in case you need any further assistance.  
 

Greetings,
Maya
the Telerik team

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

0
BRiddle
Top achievements
Rank 1
answered on 16 Aug 2011, 02:50 PM
Thank you.  

If the target row is outside of the current visible row set, simply doing a ScrollIntoViewAsync results in the target row becoming the last, bottom visible row on the resulting display.  

If the desired item is not the last one in the ItemsSource set, I'd prefer to end up with that row being presented at the top of the resulting display to better accommodate a "Find Next" potentially without scrolling again if the user wants to see the next match. 

To do that, it appears that I'll need to ScrollIntoView() to an item or item index beyond the target item and then set row .IsCurrent to highlight the original current search match.  Is there any built-in method that will instead allow me to do the scroll, but to dictate the relative visible position of the target row as something other than the last visible row?   Or do I just need to calculate the index of the row that I DO want to be at the bottom of the display as I describe?

Thanks again!
-Bob
0
Maya
Telerik team
answered on 17 Aug 2011, 09:40 AM
Hello Bob,

Generally, ScrollIntoView and ScrollIntoViewAsync methods will ensure that the item is in the view port. For the time being RadGridView does not support defining the position of the item. The reason is that there are quite many possible scenarios and requirements which cannot all be maintained. A good example is - what happens if the item you want to be displayed at the top is the last one - should it be again at the top and the rest of the grid to be empty or should it be the last one in this case. We do think of possible improvements but for the time being there is no clean solution for this.
I hope it is not such an inconvenience for you. Let me know in case you need any further assistance.
 

All the best,
Maya
the Telerik team

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

0
BRiddle
Top achievements
Rank 1
answered on 17 Aug 2011, 01:57 PM
Thank you.   I'm fine with manipulating the list to get the target row where I need it on the visible display.   I was just checking to see if there was a "ScrollIntoViewXxxxx" overload or other technique that I had missed.  

-Bob
Tags
GridView
Asked by
BRiddle
Top achievements
Rank 1
Answers by
Maya
Telerik team
BRiddle
Top achievements
Rank 1
Share this question
or