Back to Devexpress

DataViewBase.FocusedRowHandle Property

wpf-devexpress-dot-xpf-dot-grid-dot-dataviewbase-3363b504.md

latest7.5 KB
Original Source

DataViewBase.FocusedRowHandle Property

Gets or sets the focused row’s handle. This is a dependency property.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
[Browsable(false)]
public int FocusedRowHandle { get; set; }
vb
<Browsable(False)>
Public Property FocusedRowHandle As Integer

Property Value

TypeDescription
Int32

An integer value that specifies the focused row’s handle.

|

Remarks

The focused row is not displayed if the DataViewBase.NavigationStyle property is set to GridViewNavigationStyle.None.

To specify the focused row, use the FocusedRowHandle property or the DataViewBase.MoveFocusedRow method. If the specified row is not visible onscreen, a View is automatically scrolled to make the focused row visible.

The GridControl raises DataViewBase.FocusedRowHandleChanged and DataViewBase.FocusedRowHandleChanging events when the focused row handle changes.

Example

This example shows how to identify a data cell with the specified value and focus it. To do this, click the Focus Cell button.

View Example: Focus a Cell with the Specified Value

xaml
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <dxg:GridControl Name="grid" AutoGenerateColumns="AddNew">
        <dxg:GridControl.View>
            <dxg:TableView x:Name="view" AutoWidth="True" FadeSelectionOnLostFocus="False"/>
        </dxg:GridControl.View>
    </dxg:GridControl>
    <StackPanel Grid.Row="1" Orientation="Horizontal">
        <TextBlock Text="Unit Price:" TextAlignment="Right" Padding="4"/>
        <TextBox x:Name="textBox" Width="50" Margin="0,0,5,0" HorizontalAlignment="Left"/>
        <Button Content="Focus Cell" HorizontalAlignment="Left" Click="FocusCell"/>
    </StackPanel>
</Grid>
cs
void FocusCell(object sender, RoutedEventArgs e) {
    if (!double.TryParse(textBox.Text, out double textValue))
        return;
    var rowHandle = grid.FindRowByValue(grid.Columns[nameof(Product.UnitPrice)], textValue);
    if (rowHandle == DataControlBase.InvalidRowHandle) 
        return;
    grid.CurrentColumn = grid.Columns[nameof(Product.UnitPrice)];
    view.FocusedRowHandle = rowHandle;
}
vb
Private Sub FocusCell(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim textValue As Double = Nothing
    If Not Double.TryParse(Me.textBox.Text, textValue) Then Return
    Dim rowHandle = Me.grid.FindRowByValue(Me.grid.Columns(NameOf(Product.UnitPrice)), textValue)
    If rowHandle = DataControlBase.InvalidRowHandle Then Return
    Me.grid.CurrentColumn = Me.grid.Columns(NameOf(Product.UnitPrice))
    Me.view.FocusedRowHandle = rowHandle
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the FocusedRowHandle property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-expand-and-collapse-master-rows/CS/WpfApplication21/MainWindow.xaml.cs#L19

csharp
// Avoid key processing when focus is within detail views or when a group row is focused:
if (!view.IsFocusedView || view.FocusedRowHandle < 0)
    return;

how-to-create-search-window-with-find-previous-and-find-next-buttons-in-gridcontrol-t127527/CS/DevExpress.Example01/SearchBehavior/SearchWindow.xaml.cs#L222

csharp
protected void SetActiveCell() {
    this._Grid.View.FocusedRowHandle = this._FoundCells[this._CurrentCell].RowHandle;
    this._Grid.CurrentColumn = this._FoundCells[this._CurrentCell].Column;

wpf-data-grid-add-and-remove-rows-in-code/CS/AddRemoveRows/AddRemoveRowBehavior.cs#L56

csharp
void DeleteRow() {
    AssociatedObject.DeleteRow(AssociatedObject.FocusedRowHandle);
}

wpf-data-grid-expand-and-collapse-master-rows/VB/WpfApplication21/MainWindow.xaml.vb#L20

vb
' Avoid key processing when focus is within detail views or when a group row is focused:
If Not view.IsFocusedView OrElse view.FocusedRowHandle < 0 Then Return
' Process CTRL+* key combination:

how-to-create-search-window-with-find-previous-and-find-next-buttons-in-gridcontrol-t127527/VB/DevExpress.Example01/SearchBehavior/SearchWindow.xaml.vb#L216

vb
Protected Sub SetActiveCell()
    _Grid.View.FocusedRowHandle = _FoundCells(_CurrentCell).RowHandle
    _Grid.CurrentColumn = _FoundCells(_CurrentCell).Column

wpf-data-grid-add-and-remove-rows-in-code/VB/AddRemoveRows/AddRemoveRowBehavior.vb#L72

vb
Private Sub DeleteRow()
    AssociatedObject.DeleteRow(AssociatedObject.FocusedRowHandle)
End Sub

See Also

Obtain Row Handles

Focus and Navigation

DataViewBase Class

DataViewBase Members

DevExpress.Xpf.Grid Namespace