Skip to main content

DataControlBase.FindRowByValue(String, Object) Method

Searches for the value in the column and returns the handle of the corresponding row.

Namespace: DevExpress.Xpf.Grid

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

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public int FindRowByValue(
    string fieldName,
    object value
)

Parameters

Name Type Description
fieldName String

A String value that specifies the field name of the column to be searched.

value Object

An object that is the search value.

Returns

Type Description
Int32

An integer value that is the handle of the corresponding row.

Remarks

If the value is not found, the FindRowByValue method returns DataControlBase.InvalidRowHandle.

If the column contains more than one search value, the FindRowByValue method returns the handle of the first corresponding row.

If the first parameter is set to String.Empty, the FindRowByValue method searches using the whole row value.

Refer to the following help topic for more information: Obtain Row Handles.

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.

Grid - Focus a Row with the Specified Value

View Example: Focus a Cell with the Specified Value

<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>
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;
}
See Also