Creating Cells
[Previous] [Main] [Next]

 
Adding cell objects
Table cells are created using htmlTableCell. Cells appear as columns in a table, and are added to rows. Tables can have as many columns as necessary, limited only by memory and the user's tolerance for horizontal scrolling.  
 
htmlTableCell inherits from htmlGroup, so it can contain any number of other html++ or text objects, including other tables. htmlTableRow overloads the Add() method (and thus it's << insertion operator) so that text and other objects can be added as cells without explicity using htmlTableCell directly.  
 
htmlTable  table ;  
table << (htmlTableRow() << "row1,col1" << "row1,col2" )  
      << (htmlTableRow() << "row2,col1" << "row2,col2" );  
 
 
Row and Column Spanning
Cells have a unique property that allows them to occupy more space than would normally be used by a single cell, a feature called "spanning". Cells can be made to span more than one row or column, letting you create subsections within a table for displaying information that, displayed in a single cell, would cause the table to appear distorted or improperly formatted. Row and column spanning settings are specified using the RowSpan() and ColumnSpan() methods of htmlTableCell.  
 
htmlTable  table ;  
table.Border( 3 ).Align( align_center ).CellPadding( 10 ) ;  
 
htmlTableCell col2 ;  
col2.RowSpan( 2 ) ;  
col2 << "this column spans rows 1 and 2" ;  
 
table << ( htmlTableRow() << "row1,col1" << col2 )  
      << ( htmlTableRow() << "row2,col1" ) ;  
 
 

ex_tablecell1.gif  

 
 

Text Wrapping
Normally, text within cells automatically wraps to the next line if it's too wide for the cell. You can use the EnableWrap() method to enable or disable this feature on a cell-by-cell basis.  
 
Empty Cells
Occassionally, you may need to place an empty cell within a table. Normally, most browsers will omit cells that do not contain data. This is usually not a problem, unless the table or row has a background color different from the rest of the page. In such cases you must populate blank cells with something, anything, for the table to be renedered properly. Several options exist, including placing a 1-pixel transparent GIF image in the cell, but the most common approach is to include the non-breaking space code of "&nbsp;" which is more acceptable than a normal space character to the browser. Note in the example below that the non-breaking space code is encapsulated using htmlLiteral in order to prevent being encoded implicitly using htmlText.  
 
htmlTable  table ;  
table.Border( 3 ).Align( align_center )  
     .CellPadding( 10 ).BackgroundColor( COLOR_GREEN ) ;  
 
htmlTableCell col2 ;  
col2.RowSpan( 2 ) ;  
col2 << "this column spans rows 1 and 2" ;  
 
table << ( htmlTableRow() << "row1,col1" << "row1,col2" )  
      << ( htmlTableRow() << htmlLiteral("&nbsp;")   
                          << "row2,col2" ) ;  
 
 

ex_tablecell2.gif  

 


©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.