Skip to main content
Tab

ASPxGridBase.FindVisibleIndexByKeyValue(Object) Method

Returns the data item (row, card or record) visible index by its key value.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.2.dll

Declaration

public int FindVisibleIndexByKeyValue(
    object keyValue
)

Parameters

Name Type Description
keyValue Object

An object that uniquely identifies the row.

Returns

Type Description
Int32

An integer value that specifies the data item visible index. The ASPxGridView.InvalidRowIndex value if the row is not found.

Remarks

The FindVisibleIndexByKeyValue method searches for the specified data item (row, card or record) in all the data items displayed within the grid. If the data item is not found, the FindVisibleIndexByKeyValue method returns the ASPxGridView.InvalidRowIndex field value.

Example

This example shows how to focus a row that is not displayed within the current page. To do this, switch to the page that contains the required row, and then move row focus.

using DevExpress.Web.ASPxGridView;

...

protected void Button1_Click(object sender, EventArgs e) {
    // Obtain the visible index of the required row.
    int rowIndex = grid.FindVisibleIndexByKeyValue("OLDWO");
    if (rowIndex == ASPxGridView.InvalidRowIndex) return;
    if (!IsRowVisibleOnScreen(rowIndex)) {
        // Switch to the page that contains the required row.
        GoToPage(rowIndex);
    }
    // Focus the required row.
    grid.FocusedRowIndex = rowIndex;
}
bool IsRowVisibleOnScreen(int rowIndex) {
    int startIndex = grid.PageIndex * grid.SettingsPager.PageSize;
    int endIndex = startIndex + grid.SettingsPager.PageSize;
    return rowIndex >= startIndex && rowIndex < endIndex;
}
void GoToPage(int rowIndex) {
    grid.PageIndex = rowIndex / grid.SettingsPager.PageSize;
}

Online Examples

View Example: Grid View for ASP.NET Web Forms - How to focus the newly inserted row

View Example: Grid View for ASP.NET MVC - How to focus the newly inserted row

Composite Keys

If the ASPxGridBase.KeyFieldName property contains a composite key, the FindVisibleIndexByKeyValue method can accept an array of key values as a parameter.

<dx:ASPxGridView ID="Grid" runat="server" AutoGenerateColumns="False" DataSourceID="GridDataSource" KeyFieldName="OrderID;ProductName">
     <Columns>
          <dx:GridViewDataTextColumn FieldName="OrderID" VisibleIndex="0" />
          <dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1" />
          <dx:GridViewDataTextColumn FieldName="Supplier" VisibleIndex="2" />
     </Columns>
</dx:ASPxGridView>
int KeyIndex = Grid.FindVisibleIndexByKeyValue(new Object[] { 10249, "Tofu" });

An alternative way is to specify the key values that are separated by the vertical bar sign ( | ) within a string.

<dx:ASPxGridView ID="Grid" runat="server" AutoGenerateColumns="False" DataSourceID="GridDataSource" KeyFieldName="OrderID;ProductName">
     <Columns>
          <dx:GridViewDataTextColumn FieldName="OrderID" VisibleIndex="0" />
          <dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1" />
          <dx:GridViewDataTextColumn FieldName="Supplier" VisibleIndex="2" />
     </Columns>
</dx:ASPxGridView>
int KeyIndex = Grid.FindVisibleIndexByKeyValue("10249|Tofu");

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FindVisibleIndexByKeyValue(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.

See Also