[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Get Started With Data Grid and Views
   [Expand]Data Binding
    Unbound Columns
   [Expand]Data Editing and Validation
   [Expand]Filter and Search
   [Collapse]Focus and Selection Handling
     Focusing Cells
     Moving Row Focus
     Using Navigators
     Multiple Row and Cell Selection
     Multiple Row Selection via Built-In Check Column and Selection Binding
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Focusing Cells

This topic provides information on focus movement between cells at runtime, as well as information on how to specify a focused cell's appearance. Moving the cell focus at runtime may be useful when you need to facilitate end-user input. This enables you to move focus to desired cells automatically so end-users don't need to navigate through the Views themselves. This topic only describes the basics of focus movement between cells. For additional information on this subject, please refer to the Moving Row Focus topic.

Expanded Focusing Cells

The focused cell is a data cell with which the end-user can interact using the keyboard. For instance, end-users can press the F2 key to activate a cell's editor. Note: the grid control may represent master-detail data and so display several Views each of which have its own focused cell. The view, whose focused cell will actually respond to keystrokes, is determined by the grid control's GridControl.FocusedView property.

A View's focused cell is identified by its focused row and focused column. These are specified by the View's ColumnView.FocusedRowHandle and ColumnView.FocusedColumn properties respectively. Please refer to the Identifying Rows and Cards and Accessing and Identifying Columns topics for details on providing values for these properties.

Assigning a row handle to a View's ColumnView.FocusedRowHandle property scrolls the View and expands collapsed groups so that the specified row is visible on screen. This occurs also when you focus rows using other members (for instance, when using methods described in the Moving Row Focus topic). Similarly, when setting the ColumnView.FocusedColumn property to a column that is currently not visible due to scrolling, the View is scrolled horizontally to make the column visible. The ColumnView.FocusedColumn property can also accept hidden columns (whose GridColumn.Visible property value is false). In such cases, the specified column will be focused but remain invisible.

The following example shows how to locate and focus a cell in the Country column that contains 'Japan'. Note that the row is located using the ColumnView.LocateByDisplayText method. Please refer to the Filter and Search topic for details on using it.

You can handle focus movements by writing handlers for the GridControl.FocusedViewChanged, ColumnView.FocusedRowChanged and ColumnView.FocusedColumnChanged events. These events are raised when one is moving focus to another view, row and column respectively. Note also that you can prevent particular columns from being focused by end-users. Disable the desired column's OptionsColumn.AllowFocus option for this purpose.

For information on how end-users can change cell focus, refer to the Navigating Through Rows and Cells topic.

Expanded The Focused Cell's Appearance

By default, the appearance of the focused cell is specified by the GridViewAppearances.FocusedCell property.The appearance of other cells within the focused row is specified by the GridViewAppearances.FocusedRow property.

Note that you can change this default behavior by setting the GridOptionsSelection.InvertSelection property to true. In this case, the focused cell will be painted using the FocusedRow and FocusedCell appearances when browsing and editing respectively. Other cells within the focused row will have the same appearance as cells within unfocused rows.

The dotted focus rectangle can be painted around the focused cell, the entire focused row or not be displayed at all by using the GridView.FocusRectStyle property.

Expanded Online Video - WinForms Data Grid: Draw a Border Around the Focused Cell

Expanded See Also

Is this topic helpful?​​​​​​​