Ok, I understand, you mean deleting the table row (or the table itself, if it has a single row).
It's more difficult, because if you select a table row and call DeleteSelection, selected cells are cleared, but the row is not deleted.
The code is below.
Code: Select all
procedure DeleteRowsWithText(rve: TCustomRichViewEdit; const Text: String);
var table: TRVTableItemInfo;
ItemNo, ItemNo2, Data, Row, Col, RowCount, Offs, Offs2: Integer;
rve2: TCustomRichViewEdit;
begin
rve.SetSelectionBounds(0, rve.GetOffsBeforeItem(0), 0, rve.GetOffsBeforeItem(0));
while rve.SearchText(Text, [rvseoDown]) do
if rve.InplaceEditor<>nil then
begin
rve.GetCurrentItemEx(TRVTableItemInfo, rve2, TCustomRVItemInfo(table));
ItemNo := table.GetMyItemNo;
table.GetEditedCell(Row, Col);
RowCount := table.RowCount;
if RowCount = table.Cells[Row, Col].RowSpan then
begin
// deleting the whole table
rve2.SetSelectionBounds(ItemNo, 0, ItemNo, 1);
rve2.DeleteSelection;
// deleting an empty line appeared after deleting the table
SendMessage(rve2.Handle, WM_KEYDOWN, VK_DELETE, 0);
end
else
begin
// deleting rows
rve2.BeginItemModify(ItemNo, Data);
table.DeleteRows(Row, table.Cells[Row, Col].RowSpan, True);
rve2.EndItemModify(ItemNo, Data);
rve2.Change;
// if the deletion was successfull...
if table.RowCount < RowCount then
// positioning the caret to continue the search
if Row < table.RowCount then
begin
// in the next row after the deleted row(s)
table.Rows.GetMainCell(Row, 0, Row, Col);
table.EditCell(Row, Col);
end
else
begin
// or after the table
rve2.SetSelectionBounds(ItemNo, 1, ItemNo, 1);
end;
end;
end;
end;