Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Adding a table row after pressing tab in last table cell

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:C#
Version:1.0
Released:September 18, 2007
Last modified:January 11, 2008
Requirements:TX Text Control .NET with C#
Download code:tx_sample_addtablerowtab.zip Download [14.49 KB, ZIP]

Word processing applications handle the situation in which the cursor is in the final cell of a table and then the tab key is pressed by adding a new row to the table.

This functionality does not ship as standard in TX Text Control. This brief sample, however, illustrates how to implement such functionality in just a few lines of code.

If the current input position is in the last cell, the KeyPress event can be used to recognize, whether the user presses the tab key. To check, if the cursor is in the last cell, it is easy to compare the current column with the TableColumnCollection.Count property and the current row with the TableRowCollection.Count property. This is illustrated in the following code:

  1. TXTextControl.Table curTable;
  2.  
  3. if (textControl1.Tables.GetItem() == null)
  4. return;
  5. else
  6. curTable = textControl1.Tables.GetItem();
  7.  
  8. int columnCount = curTable.Columns.Count;
  9. int rowCount = curTable.Rows.Count;
  10.  
  11. if (e.KeyChar == 9 && curTable.Columns.GetItem().Column ==
  12. _columnCount && curTable.Rows.GetItem().Row == rowCount)
  13. {
  14. e.Handled = true;
  15. textControl1.Tables.GetItem().Rows.Add(TXTextControl.TableAddPosition.After, 1);
  16. }

The minimum requirements for this sample application are TX Text Control .NET trial version and C# 2005.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place