Create new tablerow on CR

<< Click to Display Table of Contents >>

Navigation:  Programming > Move cursor / select text >

Create new tablerow on CR

A) User Interface

 

Do you want to have a symbol at the end of a table row to create a new row?

 

The symbol can be accessed by pressing right at the right column.

This means the cursor now is on the table row, not a table cell. Pressing enter will create a new row.

  clip0029

WPRichText1.FormatOptions  := WPRichText1.FormatOptions + [wpTableRowIndicator];

WPRichText1.EditOptionsEx  := WPRichText1.EditOptionsEx + [wpAllowCursorInRow];

 

B) React on Keyboard press

 

If you want that a new table row is created when the user presses RETURN in a table cell you can use this example code:

 

procedure TForm1.WPRichText1KeyDown(Sender: TObject; var Key: Word;

 Shift: TShiftState);

var aRow : TParagraph;

   colnr : Integer;

begin

 aRow := WPRichText1.TableRow;

if (Key=13) and (aRow<>nil)then

begin

  if ssCtrl in Shift then

       WPRichText1.InputString(#10)

  else

  begin

       colnr := WPRichText1.TableColNumber;

       aRow := aRow.Duplicate(false, true, false, [wpParCopyStyles,wpDontCopyCellSubParagaraphs]);

       WPRichText1.ActiveParagraph := aRow.ColFirst;

       WPRichText1.TableColNumber := colnr;

       WPRichText1.ReformatAll(false, true);

  end;

   Key := 0;

end;

end;

 

Of course here refinements are possible, i.e. test wether the cursor is at the end of the cell

if WPRichText1.TableAtEndOfCell then