# Scrolling into View

Since **RadPropertyGrid** utilizes UI virtualization, it only initializes those PropertyGridFields that should be currently displayed in the view port. Thus, if one aims to bring some PropertyDefinition's PropertyGridField into view, a standard visual tree traversal will not do the work.

## The ScrollIntoViewAsync method

**ScrollIntoViewAsync(PropertyDefinition propertyDefinition, Action<PropertyGridField> finishedCallback)** handles the mentioned scenario. Invoking it for a certain **PropertyDefinition** forces RadPropertyGrid to calculate the needed scroll offset to display its PropertyGridField and then scrolls to it.

> tip After the scrolling operation is accomplished, the **finishedCallback** is executed, passing the **newly realized PropertyGridField as a parameter**.

> important ScrollIntoViewAsync is supported only when **RenderMode is set to Flat**. For more information on the different rendering modes, please check the [Layout Rendering Modes](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/layout-rendering-modes) article.

You can define RadPropertyGrid similar to:

**Example 1: Defining RadPropertyGrid with manually defined PropertyDefinitions**

```XAML
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <telerik:RadPropertyGrid Height="200" x:Name="PropertyGrid1" RenderMode="Flat" AutoGeneratePropertyDefinitions="False">
        <telerik:RadPropertyGrid.PropertyDefinitions>
            <telerik:PropertyDefinition Binding="{Binding FirstName}" GroupName="Group Name" DisplayName="FirstName"/>
            <telerik:PropertyDefinition Binding="{Binding LastName}" GroupName="Group Name" DisplayName="LastName"/>
            <telerik:PropertyDefinition Binding="{Binding Ocupation}" GroupName="Occupation" DisplayName="Occupation"/>
            <telerik:PropertyDefinition Binding="{Binding Salary}" GroupName="Occupation" DisplayName="Salary"/>
            <telerik:PropertyDefinition Binding="{Binding IsMarried}" GroupName="Personal" DisplayName="IsMarried"/>
        </telerik:RadPropertyGrid.PropertyDefinitions>
    </telerik:RadPropertyGrid>
    <Button Name="Button1"
	Grid.Row="1"
	Content="Scroll field into view "
	Click="Button1_Click"
	Margin="5"
	HorizontalAlignment="Left"/>
</Grid>
```

As to assigning the **Item of RadPropertyGrid**, please check the **Binding RadPropertyGrid to an item** section in [Getting Started with RadPropertyGrid](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/getting-started/getting-started) help article.

You can see the result after starting the application on **Figure 1**:

> caption RadPropertyGrid in sorted mode with some fields not currently visible

![Rad Property Grid Scroll Sorted 1](https://www.telerik.com/products/wpf/documentation/assets/f2611bd68c480398dc8c5ef519121f21/radpropertygrid_scroll_sorted_1.png)

Then, click on **Scroll field into view** button and execute the following code:

**Example 2: Scrolling to a particular PropertyDefinition and selecting it**

```C#
private void Button1_Click(object sender, RoutedEventArgs e)
{
    var propertyDefinition = this.PropertyGrid1.PropertyDefinitions.Where(x => x.DisplayName == "IsMarried").FirstOrDefault();
    if (propertyDefinition != null)
    {
        PropertyGrid1.ScrollIntoViewAsync(propertyDefinition, new Action<PropertyGridField>(f => f.IsSelected = true));
    }
}
```

```VB.NET
	Private Sub Button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
	    Dim propertyDefinition = Me.PropertyGrid1.PropertyDefinitions.Where(Function(x) x.DisplayName = "IsMarried").FirstOrDefault()
	    If propertyDefinition IsNot Nothing Then
	        PropertyGrid1.ScrollIntoViewAsync(propertyDefinition, New Action(Of PropertyGridField)(Sub(f) f.IsSelected = True))
	    End If
	End Sub
```

You can observe the result on **Figure 2**.

**Figure 2**: RadPropertyGrid after scrolling to a particular PropertyDefinition and selecting it![Rad Property Grid Scroll Sorted 2](https://www.telerik.com/products/wpf/documentation/assets/208ea0057536f535718f3a8c696f3e98/radpropertygrid_scroll_sorted_2.png)

## ScrollIntoViewAsync with grouping

**ScrollIntoViewAsync** can also be used in **grouped scenarios**, to bring given PropertyDefinition’s PropertyGridField in the view port.

> tip Invoking it will scroll to the group, expanding it if needed.

However, this functionality is supported only for groups that have valid Key (PropertyDefinition.GroupName). You can find more information on how to define groups in the article on [Grouping Support](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/grouping).

**Figure 3**: RadPropertyGrid in grouped mode with some fields not currently visible![Rad Property Grid Scroll Grouped 1](https://www.telerik.com/products/wpf/documentation/assets/e5e826604c9a632b9f5e697e03a48623/radpropertygrid_scroll_grouped_1.png)

Then, click on **Scroll field into view** button and execute the code from **Example 2**.

You can observe the result on **Figure 4**.

**Figure 4**: RadPropertyGrid after scrolling to a particular PropertyDefinition and selecting it![Rad Property Grid Scroll Grouped 2](https://www.telerik.com/products/wpf/documentation/assets/49f4d8cefe6278c3ffa18a01f3026c2d/radpropertygrid_scroll_grouped_2.png)

## ScrollIntoViewAsync with nested properties

When ScrollIntoView is invoked for a nested PropertyDefinition, its parent’s field gets expanded. You can find more information on how to define nested PropertyDefinitions in the article on [Nested Properties](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/nested-properties).

To guarantee that such operations will be successfully executed, both root and nested PropertyDefinitions should have a valid Binding set.

> tip It works with multiple levels of hierarchy.

For sample code on how to perform the scroll please refer to the [ScrollIntoViewAsync section](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/scrolling#the-scrollintoviewasync-method) above.

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/getting-started/getting-started)

* [Layout Rendering Modes](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/layout-rendering-modes)

* [Grouping Support](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/grouping)

* [Nested Properties](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/nested-properties)

* [Autogenerated Property Definitions](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/getting-started/autogenerated-property-definitions)
