ColumnView.BeforeLeaveRow Event
Occurs before the focused row changes. Handle this event to prevent the focused row change.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v24.2.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
#Declaration
[DXCategory("Action")]
public event RowAllowEventHandler BeforeLeaveRow
#Event Data
The BeforeLeaveRow event's data class is RowAllowEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Allow | Gets or sets a value specifying whether the current operation is allowed. |
Row |
Gets the row’s handle (position). For the Column |
#Remarks
The BeforeLeaveRow event occurs before a row loses focus. Use the e.RowHandle event parameter to identify the row. To prevent the focus change, set the e.Allow event parameter to false.
The following code snippet handles the BeforeLeaveRow
event to prevent focus from moving to the New Item Row after adding a new row:
bool allowFocusNewRow;
private void GridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {
allowFocusNewRow = e.PrevFocusedRowHandle != GridControl.NewItemRowHandle;
}
private void GridView_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e) {
if(!allowFocusNewRow) {
e.Allow = false;
allowFocusNewRow = true;
}
}