|
<< Click to display table of contents >> Table Operations |
Inserting rows and columns:
Deleting rows and columns:
▪MergeSelectedCells (see also CanMergeSelectedCells),
▪SplitSelectedCellsHorizontally,
Inserting rows and columns:
Deleting rows and columns:
▪MergeCells (also CanMergeCells)
▪DeleteEmptyRows, DeleteEmptyCols (use after cell merging).
Moving rows and columns
▪MoveRows,
▪MoveCols.
Methods for assigning table properties:
Methods for assigning row properties:
▪SetRowVAlign, SetRowKeepTogether, SetRowPageBreakBefore.
Methods for assigning cell properties:
▪SetCellColor, SetCellBorderColor, SetCellBorderLightColor;
▪SetCellBestWidth, SetCellBestHeight;
▪SetCellBackgroundImage, SetCellBackgroundImageFileName, SetCellBackgroundProperty;
If the operations above are performed before inserting the table, no addition actions are required.
If these operations are performed on table inserted in TRichView, you need to call Format method after to update the document view.
If these operations are performed on table inserted in TRichViewEdit, a special sequence of steps is required:
1.checking RichViewEdit.CanChange (especially important for data-aware versions of components);
2.obtaining the table object and its position in the editor;
(a position is defined as the item index + the editor where this table is inserted (can be a root editor or a cell inplace-editor; referred below as rve)
3.calling rve.BeginItemModify for the table
4.performing operations
5.calling rve.EndItemModify
6.calling rve.Change
The example is below.
You can group several actions so that they will be undone/redone as whole, using SetUndoGroupMode
In order to perform operation(s) on table, you need to get table object.You can do it using method
function TRichView.GetItem(ItemNo: Integer): TCustomRVItemInfo;
TCustomRVItemInfo is an ancestor class for all items of RichView, including table (TRVTableItemInfo). This method can be used for item of any type, so you need to check if it is a table (using "is" operator, or checking RichView.GetItemStyle(ItemNo)=rvsTable)
But usually, when you need to perform operations on the item at the position of the caret in the editor, you do not know if the current item is in a "root" editor, or inside a cell, or inside a cell of a table inside other cell, and so on.
In any case, you can get an item at the position of the caret with the method:
function TRichViewEdit.GetCurrentItem: TCustomRVItemInfo;
But even if the caret is inside a table, the current item will be not a table but some other item in cell-inplace editor!
The problem can be solved with the method
function TRichViewEdit.GetCurrentItemEx(
RequiredClass: TCustomRVItemInfoClass;
out ItemRichViewEdit: TCustomRichViewEdit;
out Item: TCustomRVItemInfo): Boolean;
In this method,
▪RequiredClass – set it to TRVTableItemInfo (for C++Builder: __classid(TRVTableItemInfo)).
▪Return value: True if there is an item of the given class at the position of the caret (i.e. the caret is to the left or to the right of the table), or if the caret is inside an item the given class (i.e. the caret is in a table cell).
▪Item receives the top-level item of the given class (i.e. the table).
▪ItemRichViewEdit receives the parent editor for Item (this Item is in this editor).
This editor can be "root" TRichViewEdit or a cell inplace editor.
// MyRichViewEdit:TRichViewEdit is an editor
// placed on the form at design time.
// Note: the most of operations are performed in
// rve (editor returned by GetCurrentItemEx),
// not in MyRichViewEdit.
var item: TCustomRVItemInfo;
table: TRVTableItemInfo;
Data: Integer;
rve: TCustomRichViewEdit;
ItemNo: Integer;
begin
if not MyRichViewEdit.CanChange or
not RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo, rve,
item) then
exit;
table := TRVTableItemInfo(item);
ItemNo := rve.GetItemNo(table);
rve.BeginItemModify(ItemNo, Data);
// performing some operation, for example
// table.InsertRowsBelow(1);
// or table.CellPadding := 10
rve.EndItemModify(ItemNo, Data);
rve.Change;
end;