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

Scrolling a cell into view

3 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 12 Jun 2009, 11:06 PM
I see there's an API to scroll a record into view:

RadGridView.ItemsControl.BringRecordIntoView

But I also need the ability to insure that a specific cell is also in view (if the grid has horizontal scroll bars), but I see no public API to do this.

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 15 Jun 2009, 07:55 AM
Hello Gary,

You can use this method to bring a random cell into view:

private void BringIntoView(int rowIndex, int cellIndex)  
{  
    var record = this.RadGridView1.Records[rowIndex];  
 
    this.RadGridView1.ItemsControl.BringRecordIntoView(record);  
 
    this.Dispatcher.BeginInvoke(  
        (Action) delegate 
        {  
            var row = this.RadGridView1.ItemsControl.ItemsGenerator.ContainerFromItem(record) as GridViewRow;  
            ((GridViewCell)row.Cells[cellIndex]).IsCurrent = true;  
        });  

Hope this helps.

Regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Gary
Top achievements
Rank 1
answered on 15 Jun 2009, 05:09 PM
This code only works for records that are currently visible in the grid.  If I try to focus on a cell that is in a row that is not visible then ContainerFromItem in the delegate you provided returns null.  I'm guessing this is because the records are virtualized, and the row has not yet been rendered?

Is there a way to delay execution of the delagate until after the row the cell is located in has been brought into view?  
0
Accepted
Milan
Telerik team
answered on 16 Jun 2009, 08:39 AM
Hi Gary,

The method uses the Dispatcher to delay execution but it seems that it is not working correctly.
Could you try invoking the dispatcher with a lower priority:

this.Dispatcher.BeginInvoke  
    ((Action)delegate 
    {  
        var row = this.RadGridView1.ItemsControl.ItemsGenerator.ContainerFromItem(record) as GridViewRow;  
        ((GridViewCell)row.Cells[cellIndex]).IsCurrent = true;  
    }, System.Windows.Threading.DispatcherPriority.ApplicationIdle, null 
    ); 

Hope this works.

Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Gary
Top achievements
Rank 1
Answers by
Milan
Telerik team
Gary
Top achievements
Rank 1
Share this question
or