Back to Devexpress

IRangeProvider.FromLTRB(Int32, Int32, Int32, Int32) Method

officefileapi-devexpress-dot-spreadsheet-dot-irangeprovider-dot-fromltrb-x28-system-dot-int32-system-dot-int32-system-dot-int32-system-dot-int32-x29.md

latest15.5 KB
Original Source

IRangeProvider.FromLTRB(Int32, Int32, Int32, Int32) Method

Returns a cell range by the indexes of the bounding rows and columns.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
CellRange FromLTRB(
    int leftColumnIndex,
    int topRowIndex,
    int rightColumnIndex,
    int bottomRowIndex
)
vb
Function FromLTRB(
    leftColumnIndex As Integer,
    topRowIndex As Integer,
    rightColumnIndex As Integer,
    bottomRowIndex As Integer
) As CellRange

Parameters

NameTypeDescription
leftColumnIndexInt32

An integer that is the zero-based index of the left column.

| | topRowIndex | Int32 |

An integer that is the zero-based index of the top row.

| | rightColumnIndex | Int32 |

An integer that is the zero-based index of the right column.

| | bottomRowIndex | Int32 |

An integer that is the zero-based index of the bottom row.

|

Returns

TypeDescription
CellRange

A CellRange object.

|

Remarks

Get the IRangeProvider object via the Worksheet.Range property and use the FromLTRB method to access a cell range restricted by the specified rows and columns.

To access a cell range by its reference string, use the IRangeProvider.Item property or IRangeProvider.Parse method.

Example

The table below describes how to access a cell range in a worksheet.

|

Task

|

Use one of the following members

| | --- | --- | |

Access a cell range by its reference in the A1 style or name.

|

Worksheet.Item

Workbook.Range.Item

Worksheet.Range.Item

Workbook.Range.Parse

Worksheet.Range.Parse

| |

Access a cell range by its reference in the R1C1 style.

|

Workbook.Range.Parse

Worksheet.Range.Parse

| |

Access a cell range by row and column indexes.

|

Workbook.Range.FromLTRB

Worksheet.Range.FromLTRB

| |

Create a union cell range.

|

CellRange.Union

Workbook.Range.Union

Worksheet.Range.Union

| |

Access subranges of a union cell range.

|

CellRange.Areas

|

csharp
using DevExpress.Spreadsheet;
// ...

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

// A range that includes cells from the top left cell (A1) to the bottom right cell (B5).
CellRange rangeA1B5 = worksheet["A1:B5"];

// A rectangular range that includes cells from the top left cell (C4) to the bottom right cell (E7).
CellRange rangeC4E7 = worksheet.Range["C4:E7"];

// The C4:E7 cell range located in the "Sheet3" worksheet.
CellRange rangeSheet3C4E7 = workbook.Range["Sheet3!C4:E7"];

// A range that contains a single cell (E7).
CellRange rangeE7 = worksheet.Range["E7"];

// A range that includes the entire column A.
CellRange rangeColumnA = worksheet.Range["A:A"];

// A range that includes the entire row 5.
CellRange rangeRow5 = worksheet.Range["5:5"];

// A minimal rectangular range that includes all listed cells: C6, D9 and E7.
CellRange rangeC6D9E7 = worksheet.Range.Parse("C6:D9:E7");

// A rectangular range whose left column index is 0, top row index is 0, 
// right column index is 3 and bottom row index is 2. This is the A1:D3 cell range.
CellRange rangeA1D3 = worksheet.Range.FromLTRB(0, 0, 3, 2);

// A range that includes the intersection of two ranges: C5:E10 and E9:G13. 
// This is the E9:E10 cell range.
CellRange rangeE9E10 = worksheet.Range["C5:E10 E9:G13"];

// Create a defined name for the D20:G23 cell range.
worksheet.DefinedNames.Add("Range_Name", "Sheet1!$D$20:$G$23");
// Access a range by its defined name.
CellRange rangeD20G23 = worksheet.Range["Range_Name"];

CellRange rangeA1D4 = worksheet["A1:D4"];
CellRange rangeD5E7 = worksheet["D5:E7"];
CellRange rangeRow11 = worksheet["11:11"];
CellRange rangeF7 = worksheet["F7"];

// Create a complex range via the Range.Union method.
CellRange complexRange1 = worksheet["B7:C9"].Union(rangeD5E7);

// Create a complex range via the IRangeProvider.Union method.
CellRange complexRange2 = worksheet.Range.Union(new CellRange[] { rangeRow11, rangeA1D4, rangeF7 });

// Create a complex range from multiple cell ranges separated by commas.
CellRange complexRange3 = worksheet["D15:F18, G19:H20, I21"];

// Fill the ranges with different colors.
complexRange1.FillColor = Color.LightBlue;
complexRange2.FillColor = Color.LightGreen;
complexRange3.FillColor = Color.LightPink;

// Use the Areas property to get access to a complex range's component.
complexRange2.Areas[2].Borders.SetOutsideBorders(Color.DarkGreen, BorderLineStyle.Medium);
vb
Imports DevExpress.Spreadsheet
' ...

Dim workbook As New Workbook()
Dim worksheet As Worksheet = workbook.Worksheets(0)

' A range that that includes cells from the top left cell (A1) to the bottom right cell (B5).
Dim rangeA1B5 As CellRange = worksheet("A1:B5")

' A rectangular range that includes cells from the top left cell (C4) to the bottom right cell (E7).
Dim rangeC4E7 As CellRange = worksheet.Range("C4:E7")

' The C4:E7 cell range located in the "Sheet3" worksheet.
Dim rangeSheet3C4E7 As CellRange = workbook.Range("Sheet3!C4:E7")

' A range that contains a single cell (E7).
Dim rangeE7 As CellRange = worksheet.Range("E7")

' A range that includes the entire column A.
Dim rangeColumnA As CellRange = worksheet.Range("A:A")

' A range that includes the entire row 5.
Dim rangeRow5 As CellRange = worksheet.Range("5:5")

' A minimal rectangular range that includes all listed cells: C6, D9 and E7.
Dim rangeC6D9E7 As CellRange = worksheet.Range.Parse("C6:D9:E7")

' A rectangular range whose left column index is 0, top row index is 0, 
' right column index is 3 and bottom row index is 2. This is the A1:D3 cell range.
Dim rangeA1D3 As CellRange = worksheet.Range.FromLTRB(0, 0, 3, 2)

' A range that includes the intersection of two ranges: C5:E10 and E9:G13. 
' This is the E9:E10 cell range.
Dim rangeE9E10 As CellRange = worksheet.Range("C5:E10 E9:G13")

' Create a defined name for the D20:G23 cell range.
worksheet.DefinedNames.Add("Range_Name", "Sheet1!$D$20:$G$23")
' Access a range by its defined name.
Dim rangeD20G23 As CellRange = worksheet.Range("Range_Name")

Dim rangeA1D4 As CellRange = worksheet("A1:D4")
Dim rangeD5E7 As CellRange = worksheet("D5:E7")
Dim rangeRow11 As CellRange = worksheet("11:11")
Dim rangeF7 As CellRange = worksheet("F7")

' Create a complex range via the Range.Union method.
Dim complexRange1 As CellRange = worksheet("B7:C9").Union(rangeD5E7)

' Create a complex range via the IRangeProvider.Union method.
Dim complexRange2 As CellRange = worksheet.Range.Union(New CellRange() { rangeRow11, rangeA1D4, rangeF7 })

' Create a complex range from multiple cell ranges separated by commas.
Dim complexRange3 As CellRange = worksheet("D15:F18, G19:H20, I21")

' Fill the ranges with different colors.
complexRange1.FillColor = Color.LightBlue
complexRange2.FillColor = Color.LightGreen
complexRange3.FillColor = Color.LightPink

' Use the Areas property to get access to a complex range's component.
complexRange2.Areas(2).Borders.SetOutsideBorders(Color.DarkGreen, BorderLineStyle.Medium)

The following code snippets (auto-collected from DevExpress Examples) contain references to the FromLTRB(Int32, Int32, Int32, Int32) method.

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.

web-dashboard-custom-info-exported-excel/CS/WebDashboardForm.aspx.cs#L39

csharp
sheet.Rows.Insert(0, 3);
sheet.Pictures.AddPicture(Properties.Resources.dxLogo, sheet.Range.FromLTRB(0, 0, 5, 2), true);
Cell textCell = sheet.Cells[0, 5];

wpf-spreadsheet-bind-spreadsheet-to-ms-sql-server-database/CS/WpfSpreadsheet_BindToDataSource/MainWindow.xaml.cs#L109

csharp
Worksheet sheet = spreadsheetControl.ActiveWorksheet;
CellRange rowRange = sheet.Range.FromLTRB(0, e.StartIndex, 16383, e.StartIndex + e.Count - 1);
CellRange boundRange = sheet.DataBindings[0].Range;

winforms-spreadsheet-bind-to-ms-sql-server-database/CS/SuppliersExample/Form1.cs#L90

csharp
Worksheet sheet = spreadsheetControl1.ActiveWorksheet;
CellRange rowRange = sheet.Range.FromLTRB(0, e.StartIndex, 16383, e.StartIndex + e.Count - 1);
CellRange boundRange = sheet.DataBindings[0].Range;

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

csharp
CellRange range = invoiceItems.Range;
CellRange itemRange = sheet.Range.FromLTRB(range.LeftColumnIndex, range.BottomRowIndex, range.RightColumnIndex, range.BottomRowIndex);
MoveUpLastRecord(itemRange);

spreadsheet-document-api-create-loan-amortization-schedule-within-blazor-server-app/CS/BlazorAppSpreadsheet/Code/DocumentGenerator.cs#L169

csharp
{
    range = Sheet.Range.FromLTRB(1, 11 + i, 10, 11 + i);
    range.Fill.BackgroundColor = Color.FromArgb(217, 217, 217);

winforms-dashboard-customize-exported-document/VB/CustomExportDocumentExample/Form1.vb#L48

vb
sheet.Rows.Insert(0, 3)
sheet.Pictures.AddPicture(My.Resources.dxLogo, sheet.Range.FromLTRB(0, 0, 5, 2), True)
Dim textCell As Cell = sheet.Cells(0, 5)

web-dashboard-custom-info-exported-excel/VB/WebDashboardForm.aspx.vb#L42

vb
sheet.Rows.Insert(0, 3)
sheet.Pictures.AddPicture(Properties.Resources.dxLogo, sheet.Range.FromLTRB(0, 0, 5, 2), True)
Dim textCell As Cell = sheet.Cells(0, 5)

wpf-spreadsheet-bind-spreadsheet-to-ms-sql-server-database/VB/WpfSpreadsheet_BindToDataSource/MainWindow.xaml.vb#L92

vb
Dim sheet As Worksheet = Me.spreadsheetControl.ActiveWorksheet
Dim rowRange As CellRange = sheet.Range.FromLTRB(0, e.StartIndex, 16383, e.StartIndex + e.Count - 1)
Dim boundRange As CellRange = sheet.DataBindings(0).Range

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

vb
Dim sheet As Worksheet = spreadsheetControl1.ActiveWorksheet
Dim rowRange As CellRange = sheet.Range.FromLTRB(0, e.StartIndex, 16383, e.StartIndex + e.Count - 1)
Dim boundRange As CellRange = sheet.DataBindings(0).Range

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

vb
Dim range As CellRange = invoiceItems.Range
Dim itemRange As CellRange = sheet.Range.FromLTRB(range.LeftColumnIndex, range.BottomRowIndex, range.RightColumnIndex, range.BottomRowIndex)
MoveUpLastRecord(itemRange)

See Also

How to: Access a Cell in a Worksheet

How to: Access a Row or Column

IRangeProvider Interface

IRangeProvider Members

DevExpress.Spreadsheet Namespace