windowsforms-devexpress-dot-xtragrid-dot-gridcontrol-64dc9806.md
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
[Browsable(false)]
public BaseView FocusedView { get; set; }
<Browsable(False)>
Public Property FocusedView As BaseView
| Type | Description |
|---|---|
| BaseView |
A BaseView descendant which represents the focused View.
|
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.
The code below illustrates how to obtain the value of a currently edited cell.
using DevExpress.XtraGrid.Views.Base;
ColumnView view = gridControl1.FocusedView as ColumnView;
string editingValue = null;
if (view != null && view.IsEditing)
editingValue = view.EditingValue.ToString();
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
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
{
if (gridControl.FocusedView is ColumnView view)
{
connect-winforms-grid-to-dotnetcore-service-enable-pbac/CS/WinForms.Client/MainForm.cs#L175
}
if (gridControl.FocusedView is ColumnView view)
{
winforms-grid-data-navigator-custom-button/CS/CustomButton/Form1.cs#L32
if("copy".Equals(e.Button.Tag)) {
if(gridControl1.FocusedView != null) {
gridControl1.FocusedView.CopyToClipboard();
winforms-grid-forcibly-show-cell-tooltips/CS/AlwaysShowCellHints/Form1.cs#L22
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
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
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
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
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
If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.EndEdit Then
Dim view As ColumnView = CType(gridControl1.FocusedView, ColumnView)
view.CloseEditor()
See Also