DataViewBase.FocusedRowHandleChanging Event
Occurs when the focused row handle is about to change.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v24.1.Core.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
Event Data
The FocusedRowHandleChanging event's data class is FocusedRowHandleChangingEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Handled | Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs. |
NavigationType | Gets the user action that leads to focus change. |
NewRowHandle | Gets or sets the handle of the row that gets focus. |
OldRowHandle | Gets the handle of the previously focused row. |
OriginalSource | Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs. |
RoutedEvent | Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs. |
Source | Gets the view that raised this event. |
The event data class exposes the following methods:
Method | Description |
---|---|
InvokeEventHandler(Delegate, Object) | When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs. |
OnSetSource(Object) | When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs. |
Remarks
The following code sample does not allow users to focus rows if their CanFocus property is set to false
:
private void OnFocusedRowHandleChanging(object sender, FocusedRowHandleChangingEventArgs e) {
var grid = (GridControl)e.Source.DataControl;
switch (e.NavigationType) {
case NavigationType.Prev:
case NavigationType.Last:
e.NewRowHandle = GetNextRowHandle(grid, e.NewRowHandle, x => e.Source.GetPrevRowHandle(x)) ?? e.OldRowHandle;
break;
case NavigationType.Next:
case NavigationType.First:
e.NewRowHandle = GetNextRowHandle(grid, e.NewRowHandle, x => e.Source.GetNextRowHandle(x)) ?? e.OldRowHandle;
break;
default:
e.NewRowHandle = CanFocus(grid, e.NewRowHandle) ? e.NewRowHandle : e.OldRowHandle;
break;
}
}
static int? GetNextRowHandle(GridControl grid, int rowHandle, Func<int, int> getNextRowAction) {
if (rowHandle == DataControlBase.AutoFilterRowHandle || rowHandle == DataControlBase.NewItemRowHandle)
return rowHandle;
int nextRowHandle = rowHandle;
while (grid.IsValidRowHandle(nextRowHandle)) {
if (CanFocus(grid, nextRowHandle))
return nextRowHandle;
nextRowHandle = getNextRowAction(nextRowHandle);
}
return null;
}
static bool CanFocus(GridControl grid, int rowHandle) {
return rowHandle < 0 || ((Item)grid.GetRow(rowHandle)).CanFocus;
}
Refer to the following help topics for more information: Identify Rows and Cards, Iterate Through Rows and Cells in Code.
See Also