Back to Devexpress

SpreadsheetControl.ActiveWorksheet Property

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-5300a939.md

latest8.0 KB
Original Source

SpreadsheetControl.ActiveWorksheet Property

Gets the worksheet that is currently displayed in the SpreadsheetControl.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

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

Property Value

TypeDescription
Worksheet

A Worksheet object that specifies the active worksheet.

|

Remarks

A document loaded in the SpreadsheetControl is a workbook that consists of one or more worksheets (WorksheetCollection). A worksheet that is currently displayed in the SpreadhsheetControl and available to be modified by an end-user is called an active worksheet and returned by the ActiveWorksheet property.

You can also access and change an active worksheet in code using the WorksheetCollection.ActiveWorksheet property. An end-user can switch between worksheets using the SpreadsheetControl’s Sheet Tab Selector. Before and after an active worksheet is changed via the control’s UI, the SpreadsheetControl.ActiveSheetChanging and SpreadsheetControl.ActiveSheetChanged events are raised, respectively.

Example

To set an active worksheet within a workbook, assign the corresponding Worksheet object to the WorksheetCollection.ActiveWorksheet property.

View Example

csharp
// Set the second worksheet ("Sheet2") as the active worksheet.
workbook.Worksheets.ActiveWorksheet = workbook.Worksheets["Sheet2"];
vb
' Set the second worksheet ("Sheet2") as the active worksheet.
workbook.Worksheets.ActiveWorksheet = workbook.Worksheets("Sheet2")

The following code snippets (auto-collected from DevExpress Examples) contain references to the ActiveWorksheet 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-bind-to-ms-sql-server-database/CS/SuppliersExample/Form1.cs#L41

csharp
return;
Worksheet sheet = spreadsheetControl1.ActiveWorksheet;
string cellReference = cell.GetReferenceA1();

winforms-spreadsheet-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L115

csharp
void EnableControls() {
    Worksheet sheet = spreadsheetControl1.ActiveWorksheet;
    if (sheet.Name == "Invoice") {

winforms-spreadsheet-use-formula-engine/CS/FormulaEngineTest/Form1.cs#L34

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

winforms-spreadsheet-control-create-a-data-entry-form/CS/DataEntryFormSample/MainForm.cs#L35

csharp
private void BindCustomEditors() {
    var sheet = spreadsheetControl1.ActiveWorksheet;
    // Assign custom editors to worksheet cells.

winforms-spreadsheet-use-cell-range-as-data-source/CS/RangeDataSource/Form1.cs#L29

csharp
RangeDataSourceOptions options = new RangeDataSourceOptions();
Worksheet sheet = spreadsheetControl1.ActiveWorksheet;
CellRange dataRange = sheet.Selection;

winforms-spreadsheet-bind-to-ms-sql-server-database/VB/SuppliersExample/Form1.vb#L43

vb
If cell Is Nothing Then Return
Dim sheet As Worksheet = spreadsheetControl1.ActiveWorksheet
Dim cellReference As String = cell.GetReferenceA1()

winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L106

vb
Private Sub EnableControls()
    Dim sheet As Worksheet = spreadsheetControl1.ActiveWorksheet
    If Equals(sheet.Name, "Invoice") Then

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

vb
contextCell = spreadsheetControl1.ActiveCell
    contextSheet = spreadsheetControl1.ActiveWorksheet
End Sub

winforms-spreadsheet-control-create-a-data-entry-form/VB/DataEntryFormSample/MainForm.vb#L30

vb
Private Sub BindCustomEditors()
    Dim sheet = spreadsheetControl1.ActiveWorksheet

winforms-spreadsheet-use-cell-range-as-data-source/VB/RangeDataSource/Form1.vb#L33

vb
Dim options As RangeDataSourceOptions = New RangeDataSourceOptions()
Dim sheet As Worksheet = spreadsheetControl1.ActiveWorksheet
Dim dataRange As CellRange = sheet.Selection

See Also

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace