windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-262525c8.md
Get or sets the focused row’s handle.
Namespace : DevExpress.XtraGrid.Views.Base
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[Browsable(false)]
public int FocusedRowHandle { get; set; }
<Browsable(False)>
Public Property FocusedRowHandle As Integer
| Type | Description |
|---|---|
| Int32 |
An integer value that is the handle of the focused record.
|
The following code focuses the second data row in the view:
gridView1.FocusedRowHandle = 1;
gridView1.FocusedRowHandle = 1
The following code focuses the first group row in the view:
gridView1.FocusedRowHandle = -1;
gridView1.FocusedRowHandle = -1
Tip
The following help topic describes row index types: Tutorial - Identifying Rows.
When row focus changes, ColumnView.FocusedRowChanged and ColumnView.FocusedRowObjectChanged events are raised.
See the following help topic for more information on row focus: Moving Row Focus.
Use the FocusedRowHandle property only when the Data Grid is completely initialized (for example, you can handle the form’s Shown event). To specify the focused row when the form loads, call the GridControl.ForceInitialize method to ensure that the grid control is initialized.
The following code sets the FocusedRowHandle property in the form’s Load event handler:
void Form1_Load(object sender, EventArgs e) {
gridControl1.ForceInitialize();
gridView1.FocusedRowHandle = 2;
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
gridControl1.ForceInitialize()
gridView1.FocusedRowHandle = 2
End Sub
If no row is focused, the FocusedRowHandle property returns the GridControl.InvalidRowHandle value. For instance, this value is returned when the View is empty. You can use the ColumnView.FocusInvalidRow method to temporarily hide row focus.
Note
Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the FocusedRowHandle member must not be invoked for these Views. The FocusedRowHandle member can only be used with Views that display real data within the Grid Control. Use the following methods to access these Views with which an end user interacts at runtime.
In Layout and Card Views, when you change the FocusedRowHandle property value, the ColumnView.FocusedColumn property resets to null. Manually edit the FocusedColumn property to move focus to a specific card field.
The following code snippets (auto-collected from DevExpress Examples) contain references to the FocusedRowHandle property.
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.
winforms-grid-implement-crud-operations-xpinstantfeedbacksource/CS/DXServermode2/Form1.cs#L49
{
gridView1.FocusedRowHandle = i;
oldRowsCount = gridView1.DataRowCount;
winforms-preserve-grid-state-on-refresh/CS/RefreshHelperClass.cs#L77
if(isFocused)
view.FocusedRowHandle = GetRowHandleToSelect(rowInfo);
else
winforms-grid-implement-crud-operations-linqservermodesource/CS/LinqServerModeSource/Form1.cs#L88
{
var query = nwdContext.Customers.Where<Customer>(customer => customer.CustomerID == GetCustomerIDByRowHandle(gridView1.FocusedRowHandle));
customerToEdit = query.ToList()[0];
winforms-grid-move-focused-row-up-down/CS/Form1.cs#L207
view.GridControl.Focus();
int index = view.FocusedRowHandle;
if(index <= 0) return;
winforms-mvvm-expenses-app/CS/MVVMExpenses/Views/Account/AccountsView.cs#L34
args => args.Row as DataModels.Account,
(gView, entity) => gView.FocusedRowHandle = gView.FindRow(entity));
fluentAPI.WithEvent<DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs>(gridView1, "RowCellClick")
winforms-grid-implement-crud-operations-xpinstantfeedbacksource/VB/DXServermode2/Form1.vb#L42
If Equals(customerToEdit.CustomerID, gridView1.GetRowCellValue(i, gridView1.Columns("CustomerID")).ToString()) Then
gridView1.FocusedRowHandle = i
oldRowsCount = gridView1.DataRowCount
winforms-preserve-grid-state-on-refresh/VB/RefreshHelperClass.vb#L84
If isFocused Then
view.FocusedRowHandle = GetRowHandleToSelect(rowInfo)
Else
winforms-grid-implement-crud-operations-linqservermodesource/VB/LinqServerModeSource/Form1.vb#L77
Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click
Dim keyString As String = GetCustomerIDByRowHandle(gridView1.FocusedRowHandle)
Dim query = From Customer In
winforms-grid-move-focused-row-up-down/VB/Form1.vb#L205
view.GridControl.Focus()
Dim index As Integer = view.FocusedRowHandle
If index <= 0 Then Return
winforms-mvvm-expenses-app/VB/MVVMExpenses/Views/Account/AccountsView.vb#L34
fluentAPI.WithEvent(Of DevExpress.XtraGrid.Views.Base.ColumnView, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs)(gridView1, "FocusedRowObjectChanged").SetBinding(Function(x) x.SelectedEntity, Function(args) TryCast(args.Row, DataModels.Account), Sub(gView, entity) gView.FocusedRowHandle = gView.FindRow(entity))
fluentAPI.WithEvent(Of DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs)(gridView1, "RowCellClick").EventToCommand(Sub(x) x.Edit(Nothing), Function(x) x.SelectedEntity, Function(args) (args.Clicks = 2) AndAlso (args.Button = MouseButtons.Left))
See Also