Doing selection within table cells

General TRichView support forum. Please post your questions here
Post Reply
mko
Posts: 3
Joined: Thu Sep 01, 2005 12:10 pm

Doing selection within table cells

Post by mko »

Hi,

I want to be able to delete a part of a document between two controls I've added into the document. This part is an optional part of the document, so I've got to be able to switch it off.

If the optional part is not in a table, I've got it working. But it is also possible that an optional part of a document is in a cell of a table. How can I do a selection of that part (SetSelectionBounds) where after I can possible delete it.

My strategy is first to iterate over all the items with EnuItems. When I encounter the starting and closing control, I save their ItemNo (lStart and lEnd) and use them to do a SetSelectionBounds and deleting the selection:

Code: Select all

lRichView.SetSelectionBounds(lStart, 0, lEnd, 1);
...
lRichView.DeleteSelection;
lRichView.Format;
As I said, this works fine out of a table. In a cell of a table I seem to get ItemNo's of an inplace editor (the are much to low), but how can I get to that Inplace editor while being outside the table, to do the SetSelectionBounds and deleting?

Thanks
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

TCustomRichViewEdit(RichViewEdit1.InplaceEditor) returns the inplace editor of table inside RichViewEdit1 (can be nil if inplace editor is not activated).
This editor, in its order, can have its own inplace editor (for editing cell of nested table) and so on.
The latest inplace editor is available as RichViewEdit1.TopLevelEditor (if no inplace editor is activated, then RichViewEdit1.TopLevelEditor=RichViewEdit1).

Inplace editor can be activated by calling table.EditCell or Cell.Edit. It must be activated before calling SetSelectionBounds in this cell. It's safe to activate it for cell which is already being edited, in this case these methods will do nothing.

Calling SetSelectionBounds in the main editor outside the cell automatically deactivates (destroys) inplace editors.

PS: Do not call Format after DeleteSelection. It only slows down the procedure.

PPS: It's better not to use EnumItems if you are planning to activate/deactivate inplace editors and delete items. Use a recursive procedure instead, and iterate from ItemsCount-1 downto 0.
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Example:

Code: Select all

uses CRVData, CRVFData, RVTable;
procedure TfrmTextEdit.DeleteAllPictures(RVData: TCustomRVData);
var i, r, c: Integer;
  Table: TRVTableItemInfo;
begin
  for i := RVData.ItemCount - 1 downto 0 do
    case RVData.GetItemStyle(i) of
      rvsPicture, rvsHotPicture:
        begin
          RVData := RVData.Edit;
          TCustomRVFormattedData(RVData).SetSelectionBounds(i, RVData.GetOffsBeforeItem(i), i, RVData.GetOffsAfterItem(i));
          RichViewEdit.DeleteSelection;
        end;
      rvsTable:
        begin
          Table := TRVTableItemInfo(RVData.GetItem(i));
          for r := 0 to Table.Rows.Count-1 do
            for c := 0 to Table.Rows[r].Count-1 do
              if Table.Cells[r, c] <> nil then
                DeleteAllPictures(Table.Cells[r,c].GetRVData);
        end;
    end;
end;

...
DeleteAllPictures(RichViewEdit.RVData)
...
As you can see, this code does not use InplaceEditor at all. It's because DeleteSelection deletes the selection in RichViewEdit.TopLevelEditor.
mko
Posts: 3
Joined: Thu Sep 01, 2005 12:10 pm

Post by mko »

Great,

I've got it working now. Using GetRVData on every table cell was the missing link for me.

Thanks also for the other hints
Post Reply