Back to Devexpress

ColumnView.FocusedRowHandle Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-262525c8.md

latest10.6 KB
Original Source

ColumnView.FocusedRowHandle Property

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

Declaration

csharp
[Browsable(false)]
public int FocusedRowHandle { get; set; }
vb
<Browsable(False)>
Public Property FocusedRowHandle As Integer

Property Value

TypeDescription
Int32

An integer value that is the handle of the focused record.

|

Remarks

The following code focuses the second data row in the view:

csharp
gridView1.FocusedRowHandle = 1;
vb
gridView1.FocusedRowHandle = 1

The following code focuses the first group row in the view:

csharp
gridView1.FocusedRowHandle = -1;
vb
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:

csharp
void Form1_Load(object sender, EventArgs e) {
  gridControl1.ForceInitialize();
  gridView1.FocusedRowHandle = 2;
}
vb
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.

Component-Specific Remarks

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

csharp
{
    gridView1.FocusedRowHandle = i;
    oldRowsCount = gridView1.DataRowCount;

winforms-preserve-grid-state-on-refresh/CS/RefreshHelperClass.cs#L77

csharp
if(isFocused)
    view.FocusedRowHandle = GetRowHandleToSelect(rowInfo);
else

winforms-grid-implement-crud-operations-linqservermodesource/CS/LinqServerModeSource/Form1.cs#L88

csharp
{
    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

csharp
view.GridControl.Focus();
int index = view.FocusedRowHandle;
if(index <= 0) return;

winforms-mvvm-expenses-app/CS/MVVMExpenses/Views/Account/AccountsView.cs#L34

csharp
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

vb
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

vb
If isFocused Then
    view.FocusedRowHandle = GetRowHandleToSelect(rowInfo)
Else

winforms-grid-implement-crud-operations-linqservermodesource/VB/LinqServerModeSource/Form1.vb#L77

vb
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

vb
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

vb
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

FocusedColumn

FocusedRowChanged

FocusedRowObjectChanged

Rows

Example: Focus only Data Rows

Focus Data Grid Cells

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace