Back to Devexpress

RowCollection.Remove(Int32, Func<Int32, Boolean>) Method

officefileapi-devexpress-dot-spreadsheet-dot-rowcollection-dot-remove-x28-system-dot-int32-system-dot-func-system-dot-int32-system-dot-boolean-x29.md

latest6.3 KB
Original Source

RowCollection.Remove(Int32, Func<Int32, Boolean>) Method

Removes rows that match the specified condition from the worksheet.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void Remove(
    int first,
    Func<int, bool> predicate
)
vb
Sub Remove(
    first As Integer,
    predicate As Func(Of Integer, Boolean)
)

Parameters

NameTypeDescription
firstInt32

An integer that specifies the index of a row from which the check should start.

| | predicate | Func<Int32, Boolean> |

A delegate that is the function to check for a condition in each row.

|

Example

View Example

csharp
workbook.LoadDocument("Documents\\Document.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Create a function specifying the condition to remove worksheet rows.
Func<int, bool> rowRemovalCondition = x => worksheet.Cells[x, 0].Value.NumericValue > 3.0 && worksheet.Cells[x, 0].Value.NumericValue < 14.0;

// Fill cells with data.
for (int i = 0; i < 15; i++)
{
    worksheet.Cells[i, 0].Value = i + 1;
    worksheet.Cells[0, i].Value = i + 1;
}

// Delete all rows that meet the specified condition.
//worksheet.Rows.Remove(rowRemovalCondition);

// Delete rows that meet the specified condition starting from the 7th row.
worksheet.Rows.Remove(7, rowRemovalCondition);

// Delete rows that meet the specified condition starting from the 5th row to the 14th row.
//worksheet.Rows.Remove(5, 14, rowRemovalCondition);
vb
workbook.LoadDocument("Documents\Document.xlsx")
Dim worksheet As Worksheet = workbook.Worksheets(0)
' Create a function specifying the condition to remove worksheet rows.
Dim rowRemovalCondition As Func(Of Integer, Boolean) = Function(x) worksheet.Cells(x, 0).Value.NumericValue > 3.0 AndAlso worksheet.Cells(x, 0).Value.NumericValue < 14.0

' Fill cells with data.
For i As Integer = 0 To 14
    worksheet.Cells(i, 0).Value = i + 1
    worksheet.Cells(0, i).Value = i + 1
Next i

' Delete all rows that meet the specified condition.
'worksheet.Rows.Remove(rowRemovalCondition);

' Delete rows that meet the specified condition starting from the 7th row.
worksheet.Rows.Remove(7, rowRemovalCondition)

' Delete rows that meet the specified condition starting from the 5th row to the 14th row.
'worksheet.Rows.Remove(5, 14, rowRemovalCondition);

The following code snippets (auto-collected from DevExpress Examples) contain references to the Remove(Int32, Func<Int32, Boolean>) 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.

winforms-spreadsheetcontrol-api-part-3/CS/SpreadsheetControl_API_Part03/CodeExamples/RowAndColumnActions.cs#L27

csharp
// Delete rows that meet the specified condition starting from the 7th row.
worksheet.Rows.Remove(7, rowRemovalCondition);

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/RowAndColumnActions.cs#L30

csharp
// Delete rows that meet the specified condition starting from the 7th row.
worksheet.Rows.Remove(7, rowRemovalCondition);

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.cs#L247

csharp
// Check from the 8th row.
worksheet.Rows.Remove(7, rowRemovalCondition);

winforms-spreadsheetcontrol-api-part-3/VB/SpreadsheetControl_API_Part03/CodeExamples/RowAndColumnActions.vb#L23

vb
' Delete rows that meet the specified condition starting from the 7th row.
    worksheet.Rows.Remove(7, rowRemovalCondition)
' Delete rows that meet the specified condition starting from the 5th row to the 14th row.

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.vb#L202

vb
' Check from the 8th row.
worksheet.Rows.Remove(7, rowRemovalCondition)

See Also

RowCollection Interface

RowCollection Members

DevExpress.Spreadsheet Namespace