Back to Devexpress

DataControlBase.FindRowByValue(ColumnBase, Object) Method

wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase-dot-findrowbyvalue-x28-devexpress-dot-xpf-dot-grid-dot-columnbase-system-dot-object-x29.md

latest5.1 KB
Original Source

DataControlBase.FindRowByValue(ColumnBase, 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.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public int FindRowByValue(
    ColumnBase column,
    object value
)
vb
Public Function FindRowByValue(
    column As ColumnBase,
    value As Object
) As Integer

Parameters

NameTypeDescription
columnColumnBase

The column to be searched.

| | value | Object |

An object that is the search value.

|

Returns

TypeDescription
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.

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.

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 snippet (auto-collected from DevExpress Examples) contains a reference to the FindRowByValue(ColumnBase, Object) method.

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-grid-prevent-expand-collapse-operations-for-group-rows/CS/Forbid_Expand_Collapse/MainWindow.xaml.cs#L14

csharp
if (grid.Columns[nameof(Invoice.Status)].GroupIndex == 0) {
    var childRow = grid.FindRowByValue(grid.Columns[nameof(Invoice.Status)], InvoiceStatus.Invalidated);
    var groupRow = grid.GetParentRowHandle(childRow);

See Also

FindRow(Object)

DataControlBase Class

DataControlBase Members

DevExpress.Xpf.Grid Namespace