Back to Devexpress

GridControl.FocusedView Property

windowsforms-devexpress-dot-xtragrid-dot-gridcontrol-64dc9806.md

latest8.4 KB
Original Source

GridControl.FocusedView Property

Gets or sets the View which is currently focused.

Namespace : DevExpress.XtraGrid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

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

Property Value

TypeDescription
BaseView

A BaseView descendant which represents the focused View.

|

Remarks

When the grid control is working in master-detail mode, it can display a number of Views simultaneously. For instance, it can display the main View together with expanded detail clones. The FocusedView property can be used to determine which View currently has focus. Setting this property moves focus to the specified View. To specify the focused cell within a View use the ColumnView.FocusedColumn and ColumnView.FocusedRowHandle properties.

The FocusedView property merely indicates the internal grid control’s focus position. To determine whether the grid control is focused read its GridControl.IsFocused property’s value. Whether a particular View has focus can be determined by inspecting the BaseView.IsFocusedView property’s value.

When moving focus between the Views the GridControl.FocusedViewChanged event is raised. When a View receives or loses focus, the BaseView.GotFocus and BaseView.LostFocus events are raised, respectively.

Example

The code below illustrates how to obtain the value of a currently edited cell.

csharp
using DevExpress.XtraGrid.Views.Base;

ColumnView view = gridControl1.FocusedView as ColumnView;
string editingValue = null;
if (view != null && view.IsEditing)
    editingValue = view.EditingValue.ToString();
vb
Imports DevExpress.XtraGrid.Views.Base

Dim view As ColumnView = CType(GridControl1.FocusedView, ColumnView)
Dim editingValue As String = Nothing 
If view IsNot Nothing And view.IsEditing Then 
    editingValue = view.EditingValue.ToString()
End If

The following code snippets (auto-collected from DevExpress Examples) contain references to the FocusedView 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-auto-expand-new-master-row/CS/Q205071/Form1.cs#L29

csharp
if (e.Button.Tag != null && e.Button.Tag.ToString() == "update") {
    if (gridControl1.FocusedView == gridView1) nwindDataSet.Categories.AcceptChanges();
    else if (gridControl1.FocusedView.ParentView == gridView1) nwindDataSet.Products.AcceptChanges();

connect-winforms-grid-to-dotnetcore-service-enable-editing/CS/WinForms.Client/MainForm.cs#L48

csharp
{
    if (gridControl.FocusedView is ColumnView view)
    {

connect-winforms-grid-to-dotnetcore-service-enable-pbac/CS/WinForms.Client/MainForm.cs#L175

csharp
}
if (gridControl.FocusedView is ColumnView view)
{

winforms-grid-data-navigator-custom-button/CS/CustomButton/Form1.cs#L32

csharp
if("copy".Equals(e.Button.Tag)) {
    if(gridControl1.FocusedView != null) {
        gridControl1.FocusedView.CopyToClipboard();

winforms-grid-forcibly-show-cell-tooltips/CS/AlwaysShowCellHints/Form1.cs#L22

csharp
if(e.Info == null && e.SelectedControl == gridControl1) {
    GridView view = gridControl1.FocusedView as GridView;
    GridHitInfo info = view.CalcHitInfo(e.ControlMousePosition);

connect-winforms-grid-to-dotnetcore-service-enable-editing/VB/WinForms.Client/MainForm.vb#L42

vb
Private Async Sub addItemButton_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs)
    If TypeOf gridControl.FocusedView Is ColumnView Then
        Dim view As ColumnView = DirectCast(gridControl.FocusedView, ColumnView)

winforms-grid-auto-expand-new-master-row/VB/Q205071/Form1.vb#L27

vb
If e.Button.Tag IsNot Nothing AndAlso Equals(e.Button.Tag.ToString(), "update") Then
    If gridControl1.FocusedView Is gridView1 Then
        nwindDataSet.Categories.AcceptChanges()

winforms-grid-data-navigator-custom-button/VB/CustomButton/Form1.vb#L31

vb
If "copy".Equals(e.Button.Tag) Then
    If gridControl1.FocusedView IsNot Nothing Then
        gridControl1.FocusedView.CopyToClipboard()

winforms-grid-forcibly-show-cell-tooltips/VB/AlwaysShowCellHints/Form1.vb#L24

vb
If e.Info Is Nothing AndAlso e.SelectedControl Is gridControl1 Then
    Dim view As GridView = TryCast(gridControl1.FocusedView, GridView)
    Dim info As GridHitInfo = view.CalcHitInfo(e.ControlMousePosition)

winforms-grid-linq-to-sql-master-detail/VB/LinqWithEditing/Form1.vb#L33

vb
If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.EndEdit Then
    Dim view As ColumnView = CType(gridControl1.FocusedView, ColumnView)
    view.CloseEditor()

See Also

DefaultView

IsFocused

FocusedViewChanged

MainView

BaseView

GridControl Class

GridControl Members

DevExpress.XtraGrid Namespace