Back to Devexpress

ASPxGridViewBehaviorSettings.AllowFocusedRow Property

aspnet-devexpress-dot-web-dot-aspxgridviewbehaviorsettings-73ca24b7.md

latest4.8 KB
Original Source

ASPxGridViewBehaviorSettings.AllowFocusedRow Property

Specifies whether row focus is enabled.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(false)]
public bool AllowFocusedRow { get; set; }
vb
<DefaultValue(False)>
Public Property AllowFocusedRow As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

true to enable row focus; otherwise, false.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to AllowFocusedRow
ASPxGridView

.SettingsBehavior .AllowFocusedRow

| | GridViewProperties |

.SettingsBehavior .AllowFocusedRow

|

Remarks

Set the AllowFocusRow property to true to enable row focus. When focus changes, the control raises the server ASPxGridView.FocusedRowChanged or the client ASPxClientGridView.FocusedRowChanged event (based on the ProcessFocusedRowChangedOnServer property value) and sets the FocusedRowIndex property to the index of the focused row.

The control can focus only one row at a time within the current page. If you navigate to another page, the row loses focus. To select multiple rows within different pages, use row selection.

When row focus is disabled, the control behaves as follows:

  • The FocusedRowIndex property returns -1.
  • The FocusedRowChanged event does not fire.
  • Focused row style settings are not in effect.

To identify the row being edited, use the EditingRowVisibleIndex property.

Limitations

Web Forms Example

The examples below show how to use the AllowFocusedRow property.

aspx
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
    ClientInstanceName="grid" KeyFieldName="CategoryID">
    <SettingsBehavior AllowFocusedRow="true" />
    <SettingsDetail ShowDetailRow="True" AllowOnlyOneMasterRowExpanded="true" />
    <ClientSideEvents DetailRowExpanding="OnDetailRowExpanding" />
    <Columns>
        <%--...--%>
    </Columns>
    <Templates>
        <DetailRow>
            <dx:ASPxGridView ID="ASPxGridView2" runat="server" KeyFieldName="ProductID"
                AutoGenerateColumns="False">
                <Columns>
                    <%--...--%>
                </Columns>
            </dx:ASPxGridView>
        </DetailRow>
    </Templates>
</dx:ASPxGridView>
js
function OnDetailRowExpanding(s, e) {
    grid.SetFocusedRowIndex(e.visibleIndex);
}

MVC Example

cshtml
@Html.DevExpress().GridView(settings => {
    settings.Name = "GridView";
    settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" };
    settings.SettingsPager.PageSize = 5;

    settings.KeyFieldName = "EmployeeID";
    settings.Columns.Add("LastName");
    settings.Columns.Add("FirstName");
    settings.Columns.Add("City");
    settings.Columns.Add("Country");

    settings.PreRender = (s, e) => {
        var sender = (MVCxGridView)s;
        // Set the zero-based index of the focused row. 
        sender.FocusedRowIndex = 6;
    };
    // Enable row focus. 
    settings.SettingsBehavior.AllowFocusedRow = true;
}).Bind(Model).GetHtml()

See Also

ASPxGridViewBehaviorSettings Class

ASPxGridViewBehaviorSettings Members

DevExpress.Web Namespace