Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [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]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Collapse]Spreadsheet
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Events
   [Expand]Mail Merge Overview
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Shortcuts
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheets
    [Expand]Rows and Columns
    [Collapse]Cells
      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]Formulas
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Tables
    [Expand]Pivot Tables
    [Expand]Printing
    [Expand]Pictures
    [Expand]Charts
    [Expand]Protection
    [Expand]Customization
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap 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]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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 Range 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.

How would you rate this topic?​​​​​​​