[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
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Tables
   [Expand]Charts and Graphics
   [Expand]Mail Merge
    Operation Restrictions
    Find and Replace
   [Expand]Visual Elements
   [Expand]Keyboard Shortcuts
    [Expand]Rows and Columns
      How to: Access a Cell in a Worksheet
      How to: Access a Range of Cells
      How to: Obtain Selected Range and Active Cell
      How to: Insert a Cell or Cell Range
      How to: Delete a Cell or Range of Cells
      How to: Create a Named Range of Cells
      How to: Change a Cell or Cell Range Value
      How to: Convert Objects to Cell Values and Cell Values to Objects
      How to: Add Formulas to Cells
      How to: Add a Hyperlink to a Cell
      How to: Create, Edit and Copy Cell Comments
      How to: Clear Cells of Content, Formatting, Hyperlinks and Comments
      How to: Copy Cell Data Only, Cell Style Only, or Cell Data with Style
      How to: Merge Cells or Split Merged Cells
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Pivot Tables
  [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)

How to: Obtain Selected Range and Active Cell

To access a range of cells in a worksheet (e.g., to format, merge, insert or delete cells), an end-user selects this range. You can programmatically get or set the selected cell range using the SpreadsheetControl.Selection or Worksheet.Selection property. Another way to select the cell range is to use the range's RangeExtensions.Select extension method, defined by the RangeExtensions class. This extension method is accessible as a method of the CellRange object and called by using the instance method syntax.

One of the cells within a range selected by an end-user is the active cell. When an end-user types something, data is inserted into this cell. Usually, the active cell is the top left cell in the selected range. However, it can be any cell within the current selection. End-users can specify the position of the active cell by pressing TAB, SHIFT+TAB, ENTER or SHIFT+ENTER. To specify the active cell in code, use the SpreadsheetControl.ActiveCell, SpreadsheetControl.SelectedCell or Worksheet.SelectedCell property.

An end-user can also select multiple non-adjacent cells or cell ranges in the worksheet simultaneously by holding down the CTRL key when selecting cell ranges. To get or set the list of selected ranges in code, use the SpreadsheetControl.GetSelectedRanges/SpreadsheetControl.SetSelectedRanges or Worksheet.GetSelectedRanges/Worksheet.SetSelectedRanges methods. If there is more than one range selected in the worksheet, the Selection property returns the range that contains the active cell (e.g., E3:F7 in the image below).

The SpreadsheetControl object's members mentioned above provide access to cell selection and the active cell in the active worksheet. To manage cell selection in any other worksheet, use members of the corresponding Worksheet object. The following example demonstrates how to set borders around cell ranges currently selected by an end-user, and apply a color to the active cell.

The SpreadsheetControl.SelectionChanged event occurs each time an end-user selects cells in an active worksheet.

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