Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

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.v19.1.Core.dll

Declaration

Range FromLTRB(
    int leftColumnIndex,
    int topRowIndex,
    int rightColumnIndex,
    int bottomRowIndex
)

Parameters

Name Type Description
leftColumnIndex Int32

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

Type Description
Range

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

SpreadsheetControl_Range_BoundRowsColumns

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

Example

This example demonstrates how to access ranges of cells in a worksheet. There are several ways to accomplish this.

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).
Range rangeA1B5 = worksheet["A1:B5"];

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

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

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

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

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

// A minimal rectangular range that includes all listed cells: C6, D9 and E7.
Range 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.
Range 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.
Range 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.
Range rangeD20G23 = worksheet.Range["Range_Name"];

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

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

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

// Create a complex range from multiple cell ranges separated by commas.
Range 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);

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.

See Also