Monday, September 08, 2008  



 FarPoint Technologies
 (800) 645-5913

 fpsales@fpoint.com



     
 »Spread for Windows Forms » Product Tour » Appearance » Cell

Previous Customizing the Appearance of a Cell Next


  Back to Top
 Working with the Active Cell
The active cell is the cell that currently receives any user interaction. You can specify the active cell programmatically using the SetActiveCell method of the SheetView class. You can also use the ActiveCell property to find the active cell coordinates. You can also change the focus indicator.

// Set the active cell
fpSpread1.ActiveSheet.SetActiveCell(2, 2, false);

' Set the active cell
FpSpread1.ActiveSheet.SetActiveCell(2, 2, False)


  Back to Top
 Coloring a Cell
You can set the background and foreground (text) colors for a cell or for a group of cells. You can also specify these colors if the cells are selected using SelectionBackColor and SelectionForeColor for the sheet. You can also specify a different color (for background or for text) in locked cells

' Sets the background color and text color for the second cell, and sets the colors for locked cells, and sets the colors for selections.
FpSpread1.ActiveSheet.Cells(0,1).Value = "This is default."
FpSpread1.ActiveSheet.Cells(1,1).Value = "This is custom."
FpSpread1.ActiveSheet.Cells(2,1).Value = "This is locked."
FpSpread1.ActiveSheet.Cells(3,1).Value = "This is selected."

FpSpread1.ActiveSheet.Cells(1,1].BackColor = Color.LimeGreen
FpSpread1.ActiveSheet.Cells(1,1].ForeColor = Color.Yellow

FpSpread1.ActiveSheet.Cells(2,1].Locked = True
FpSpread1.ActiveSheet.Protect = True
FpSpread1.ActiveSheet.LockBackColor = Color.Brown
FpSpread1.ActiveSheet.LockForeColor = Color.Orange

FpSpread1.ActiveSheet.SelectionStyle = FarPoint.Win.Spread.SelectionStyles.SelectionColors
FpSpread1.ActiveSheet.SelectionPolicy = FarPoint.Win.Spread.Model.SelectionPolicy.Range
FpSpread1.ActiveSheet.SelectionUnit = FarPoint.Win.Spread.Model.SelectionUnit.Cell
FpSpread1.ActiveSheet.SelectionBackColor = Color.Pink
FpSpread1.ActiveSheet.SelectionForeColor = Color.Red


  Back to Top
 Aligning Cell Contents
You can determine how the contents are aligned in a cell or in a group of cells.

// Set the alignment of the first cell (A1) to be right-bottom aligned
fpSpread1.Sheets[0].Cells[0,0].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Right;
fpSpread1.Sheets[0].Cells[0,0].VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Bottom;

' Set the alignment of the first cell (A1) to be right-bottom aligned
FpSpread1.Sheets(0).Cells(0,0).HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Right
FpSpread1.Sheets(0).Cells(0,0).VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Bottom


  Back to Top
 Resizing the Cell to Fit the Data
You can resize the cell based on the length of the data in the cell. The size of the cell with the largest data is called the preferred size.



  Back to Top
 Customizing Cell Borders
You can customize the appearance of the cells by setting borders for a cell or range of cells. Different border styles let you set different options. For example, the complex border lets you set different styles of border display for each side of the cell. borders. For each of the border styles, you can turn off the display of the border on any side of the cell.

The following lists the different border styles you can use:
Beveled, Complex, Compound, Double-line, Single-line border, Rounded-edge: single-line

// Create the bevel border FarPoint.Win.BevelBorder bevelBorder = new FarPoint.Win.BevelBorder(FarPoint.Win.BevelBorderType.Raised, Color.Cyan, Color.DarkCyan);
// Set cell B3 border to the bevel border
fpSpread1.Sheets[0].Cells[4, 3].Border = bevelBorder;

' Create the bevel border
Dim bevelBorder As New FarPoint.Win.BevelBorder(FarPoint.Win.BevelBorderType.Raised, Color.Cyan, Color.DarkCyan)
' Set cell B3 border to the bevel border
FpSpread1.Sheets(0).Cells(4, 3).Border = bevelBorder



  Back to Top
 Creating a Complex Border with Multiple Lines
You can create a border of a cell with multiple lines using the complex border. For example, you could create a ComplexBorderSide that has two underlines (two lines with a blank space in between) each taking a third of the width of the pen.

// Create a new complex border side with two lines FarPoint.Win.ComplexBorderSide bottomBorder = new FarPoint.Win.ComplexBorderSide(true, Color.Black, 3, System.Drawing.Drawing2D.DashStyle.Solid, null, new Single[] {0f, 0.33f, 0.66f, 1f});
fpSpread1.Sheets[0].Cells[3, 7].Border = new FarPoint.Win.ComplexBorder(null, null, null, bottomBorder);

' Create a new complex border side with two lines
Dim bottomBorder As New FarPoint.Win.ComplexBorderSide(Color.Black, 3, System.Drawing.Drawing2D.DashStyle.Solid, Nothing, New Single() {0, 0.33, 0.66, 1})
FpSpread1.Sheets(0).Cells(3, 7).Border = New FarPoint.Win.ComplexBorder(Nothing, Nothing, Nothing, bottomBorder)


  Back to Top
 Spanning Cells
You can group cells together to form one large cell. This is called a spanning cells and the large cell that is created is called a cell span. You can add spans in headers or in data cells. Creating a span of cells creates one large cell where there had previously been several.

// Span six cells
fpSpread1.ActiveSheet.AddSpanCell(1, 1, 2, 3);

' Span six cells
fpSpread1.ActiveSheet.AddSpanCell(1, 1, 2, 3)


  Back to Top
 Merging Cells Automatically
You can have Spread automatically merge cells between columns or between rows if the cells have the same value based on the policy that you set. The control can automatically combine cells that have the same contents. You might want to do this, for example, when bound to a database.

// Set the row and column merge policies for all rows and all columns
fpSpread1.Sheets[0].SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);
fpSpread1.Sheets[0].SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);

' Set the row and column merge policies for all rows and all columns
FpSpread1.Sheets(0).SetRowMerge(-1,FarPoint.Win.Spread.Model.MergePolicy.Always)
FpSpread1.Sheets(0).SetColumnMerge(-1,FarPoint.Win.Spread.Model.MergePolicy.Always)


  Back to Top
 Allowing Cell Data to Overflow
You can determine how the contents of a cell or a group of cells overflow into adjoining cells.

// Set the control to allow cells to overflow but only up to the maximum of 130 pixels
fpSpread1.AllowCellOverflow = true;
fpSpread1.SetMaximumCellOverflowWidth(130);

' Set the control to allow cells to overflow but only up to the maximum of 130 pixels
FpSpread1.AllowCellOverflow = True
FpSpread1.SetMaximumCellOverflowWidth(130)


  Back to Top
 Creating and Applying a Style for Cells
You can quickly customize the appearance of a cell or range of cells (or rows or columns) by applying a "style". You can create your own named style and save it to use again, similar to a template. The style includes appearance settings that apply to cells, such as background color, text color, font, borders, and cell type. A style can be applied to any number of cells. Just as a skin can be applied to a sheet, so a style can be applied to cells.


Previous Customizing the Appearance of a Cell Next

    
 Have a question?
Have a Question? Ask Us!
Subscribe to the RSS feed!RSS Subscribe
 

 
Learn about the new Roadshow now!

Tour Home
Overview
Appearance
User Interaction
Cell Types
Formulas
Managing Data
Data Binding
Import/Export
Printing
Keyboard Interaction
Shapes
Models
Spread Designer
 
Map

Copyright © 1991-2007 FarPoint Technologies, Inc. All rights reserved. All names are property of their respective owners.