Back to Devexpress

SpreadsheetControl.ActiveCell Property

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-c4fafba2.md

latest7.4 KB
Original Source

SpreadsheetControl.ActiveCell Property

Returns an active cell in the active worksheet.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
[Browsable(false)]
public Cell ActiveCell { get; }
vb
<Browsable(False)>
Public ReadOnly Property ActiveCell As Cell

Property Value

TypeDescription
Cell

Specifies an active cell.

|

Remarks

The SpreadsheetControl.Selection property specifies the selected cell range in the active worksheet (for instance, B3:F9 in the image below). The SpreadsheetControl.SelectedCell property specifies an active cell where data is inserted when a user types (E7 in the image below). Use the ActiveCell property to obtain this cell. Selection can be a cell or cell range, while SelectedCell is always a single cell within the current selection.

The following code specifies the cell selection and an active cell as shown in the image above.

csharp
using DevExpress.Spreadsheet;
// ...

IWorkbook workbook = spreadsheetControl1.Document;
Worksheet activeSheet = workbook.Worksheets.ActiveWorksheet;

// Specify the selected range in the active worksheet.
spreadsheetControl1.Selection = activeSheet.Range["B3:F9"];
// Specify an active cell in the active worksheet.
spreadsheetControl1.SelectedCell = activeSheet.Cells["E7"];
vb
Imports DevExpress.Spreadsheet
' ...

Dim workbook As IWorkbook = spreadsheetControl1.Document
Dim activeSheet As Worksheet = workbook.Worksheets.ActiveWorksheet

' Specify the selected range in the active worksheet.
spreadsheetControl1.Selection = activeSheet.Range("B3:F9")
' Specify an active cell in the active worksheet.
spreadsheetControl1.SelectedCell = activeSheet.Cells("E7")

Note

You can also use the Worksheet.Selection and Worksheet.SelectedCell properties to specify the selected range and active cell in a worksheet.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ActiveCell 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-spreadsheet-use-formula-engine/CS/FormulaEngineTest/Form1.cs#L33

csharp
{
    contextCell = spreadsheetControl1.ActiveCell;
    contextSheet = spreadsheetControl1.ActiveWorksheet;

winforms-spreadsheet-how-to-edit-rich-text/CS/SpreadsheetRichText/Form1.cs#L45

csharp
{
    Cell activeCell = spreadsheetControl.ActiveCell;
    if (activeCell.Value.IsEmpty || (!activeCell.HasFormula && activeCell.Value.IsText))

how-to-bind-a-worksheet-to-a-generic-list-or-a-bindinglist-data-source/CS/DataBindingToListExample/Form1.cs#L23

csharp
private void barBtnBindWeather_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    BindWeatherReportToTable(MyWeatherReportSource.Data, spreadsheetControl1.ActiveCell);
}

winforms-spreadsheet-custom-draw-example/CS/WindowsFormsApp1/Form1.cs#L113

csharp
// Specify the background color for the active cell.
if (e.Cell == spreadsheetControl1.ActiveCell)
{

winforms-spreadsheet-use-formula-engine/VB/FormulaEngineTest/Form1.vb#L31

vb
Private Sub spreadsheetControl1_DocumentLoaded(ByVal sender As Object, ByVal e As EventArgs)
    contextCell = spreadsheetControl1.ActiveCell
    contextSheet = spreadsheetControl1.ActiveWorksheet

winforms-spreadsheet-how-to-edit-rich-text/VB/SpreadsheetRichText/Form1.vb#L39

vb
If e.MenuType = DevExpress.XtraSpreadsheet.SpreadsheetMenuType.Cell Then
    Dim activeCell As Cell = spreadsheetControl.ActiveCell
    If activeCell.Value.IsEmpty OrElse (Not activeCell.HasFormula AndAlso activeCell.Value.IsText) Then

how-to-bind-a-worksheet-to-a-generic-list-or-a-bindinglist-data-source/VB/DataBindingToListExample/Form1.vb#L25

vb
Private Sub barBtnBindWeather_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles barBtnBindWeatherListToTable.ItemClick
    BindWeatherReportToTable(MyWeatherReportSource.Data, spreadsheetControl1.ActiveCell)
End Sub

winforms-spreadsheet-custom-draw-example/VB/CustomDrawExample/Form1.vb#L207

vb
' Specify the background color for the active cell.
If e.Cell Is spreadsheetControl1.ActiveCell Then
    e.BackColor = Color.FromArgb(50, 200, 44, 74)

See Also

Selection

SelectedCell

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace