wpf-devexpress-dot-xpf-dot-grid-dot-dataviewbase-dd62aa12.md
Occurs when the focused row handle is about to change.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public event FocusedRowHandleChangingEventHandler FocusedRowHandleChanging
Public Event FocusedRowHandleChanging As FocusedRowHandleChangingEventHandler
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. |
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;
}
Private Sub OnFocusedRowHandleChanging(ByVal sender As Object, ByVal e As FocusedRowHandleChangingEventArgs)
Dim grid = CType(e.Source.DataControl, GridControl)
Select Case e.NavigationType
Case NavigationType.Prev, NavigationType.Last
e.NewRowHandle = If(GetNextRowHandle(grid, e.NewRowHandle, Function(x) e.Source.GetPrevRowHandle(x)), e.OldRowHandle)
Case NavigationType.[Next], NavigationType.First
e.NewRowHandle = If(GetNextRowHandle(grid, e.NewRowHandle, Function(x) e.Source.GetNextRowHandle(x)), e.OldRowHandle)
Case Else
e.NewRowHandle = If(CanFocus(grid, e.NewRowHandle), e.NewRowHandle, e.OldRowHandle)
End Select
End Sub
Private Shared Function GetNextRowHandle(ByVal grid As GridControl, ByVal rowHandle As Integer, ByVal getNextRowAction As Func(Of Integer, Integer)) As Integer?
If rowHandle = DataControlBase.AutoFilterRowHandle OrElse rowHandle = DataControlBase.NewItemRowHandle Then Return rowHandle
Dim nextRowHandle As Integer = rowHandle
While grid.IsValidRowHandle(nextRowHandle)
If CanFocus(grid, nextRowHandle) Then Return nextRowHandle
nextRowHandle = getNextRowAction(nextRowHandle)
End While
Return Nothing
End Function
Private Shared Function CanFocus(ByVal grid As GridControl, ByVal rowHandle As Integer) As Boolean
Return rowHandle < 0 OrElse (CType(grid.GetRow(rowHandle), Item)).CanFocus
End Function
Refer to the following help topics for more information: Identify Rows and Cards, Iterate Through Rows and Cells in Code.
See Also