Spread Windows Forms 11.0 Product Documentation
Setting a Hyperlink Cell
Spread Windows Forms 11.0 Product Documentation > Developer's Guide > Customizing Interaction with Cell Types > Working with Graphical Cell Types > Setting a Hyperlink Cell

You can use a hyperlink cell to contain text that functions as a single hyperlink or multiple hyperlinks. The destination of the hyperlink can be any universal resource locator (URL). For example:

Customizing Links

You can specify how much of the text functions as a hyperlink and the rest displays as ordinary text. You can specify the appearance of the hyperlinked text, customize the color of the link that has been followed (visited or clicked) and whether to use the text for the hyperlink from the Data Model.

Property Customization
BackgroundImage Sets the background graphic image.
Link Sets the destination URL.
LinkArea Sets the area of the text that is the hyperlink.
LinkAreas Sets the area of the text that is the hyperlink.
LinkColor Sets the color of links (before they are followed).
Links Sets the hyperlinks.
Text Sets the label of the hyperlink, that is, what appears in the cell.
VisitedLinkColor Sets the color of followed links.
UseModelValueAsText Gets a value indicating whether to use the text for the hyperlink from the Data Model.

Making Links in Text

To create a cell that acts like a hyperlink, use the HyperLinkCellType class. Create a hyperlink cell using the following procedure. The results of the procedure, both normal and followed links, are shown in the following figure.

Hyperlink Text Before Clicking Link Hyperlink Text After Following Link

Hyperlink with Unvisited Link

Hyperlink with Visited Link

The following figure displays a hyperlink cell with multiple links.

Hyperlink Cell with Multiple Links

For more information on the properties and methods of this cell type, refer to the HyperLinkCellType class.

For more information on the corresponding event when a user clicks on a hyperlink, refer to the FpSpread.ButtonClicked event.

Sorting and Filtering Hyperlinks by Text

After creating hyperlinks, you can also perform sorting and filtering operations on them by text values. 

To do this, you can use the UseModelValueAsText property. By default, the value of this property is a boolean false. When this property is set to true, it fetches the text value from the Data Model and sets this value in the cell of HyperlinkCellType. The text values (fetched from the Data Model) entered in the cells can later be sorted and filtered as and when desired, like other celltypes.

Using the Properties Window

  1. At design time, in the Properties window, select the Spread component.
  2. Select the Sheets property.
  3. Click the button to display the SheetView Collection Editor.
  4. In the Members list, select the sheet in which the cells appear.
  5. In the property list, select the Cells property and then click the button to display the Cell, Column, and Row Editor.
  6. Select the cells for which you want to set the cell type.
  7. In the property list, select the CellType property and choose the HyperLink cell type.
  8. Expand the list of properties under the CellType property. Select and set these specific properties as needed.
  9. Click OK to close the Cell, Column, and Row Editor.
  10. Click OK to close the SheetView Collection Editor.

Using Code

  1. Define the hyperlink cell by creating an instance of the HyperLinkCellType class.
  2. Be sure to set the size of the cell so that all the text including the hyperlink are visible and display properly.
  3. Specify the text that appears in the cell by specifying the Text property for the HyperLinkCellType object. Specify how much of the text is hyperlink using the LinkArea property for that object.
  4. Specify the appearance of the hyperlink by setting properties, such as LinkColor.
  5. Assign the hyperlink cell type to a cell or range of cells by setting the CellType property for a cell, column, row, or style to the HyperLinkCellType object.
  6. If you want to perform sort/filter operations on the hyperlink cell, set the UseModelValueAsText property to true in order to indicate that the text for the hyperlink must be used from the data model.

Example

This example code sets the size of the cell (by column and row), creates a hyperlink button, and specifies the destination URL.

Also, it shows how to use the UseModelValueAsText property to indicate that the text value for the hyperlink must be fetched from the Data Model.

C#
Copy Code
fpSpread1.ActiveSheet.Columns[1].Width = 145;
fpSpread1.ActiveSheet.Rows[1].Height = 45;
FarPoint.Win.Spread.CellType.HyperLinkCellType hlnkcell = new FarPoint.Win.Spread.CellType.HyperLinkCellType();
hlnkcell.Text ="Click to See Our Web Site";
hlnkcell.Link ="http://www.grapecity.com";
hlnkcell.LinkArea = new LinkArea(9,16);
hlnkcell.LinkColor = Color.DarkGreen;
hlnkcell.VisitedLinkColor = Color.Chartreuse;
fpSpread1.ActiveSheet.Cells[1, 1].CellType = hlnkcell;
// Set value in the Data Model
fpSpread1.ActiveSheet.SetValue(1,1,"Click to see our website");
hlnkcell.UseModelValueAsText = true; // Indicates that text must be used from data model
VB
Copy Code
fpSpread1.ActiveSheet.Columns(1).Width = 145
fpSpread1.ActiveSheet.Rows(1).Height = 45
Dim hlnkcell As New FarPoint.Win.Spread.CellType.HyperLinkCellType()
hlnkcell.Text = "Click to See Our Web Site"
hlnkcell.Link ="http://www.grapecity.com"
hlnkcell.LinkArea = New LinkArea(9,16)
hlnkcell.LinkColor = Color.DarkGreen
hlnkcell.VisitedLinkColor = Color.Chartreuse
fpSpread1.ActiveSheet.Cells(1, 1).CellType = hlnkcell
' Set value in the Data Model
fpSpread1.ActiveSheet.SetValue(1, 1, "Click to see our website")
' Indicates that text must be used from data model
hlnkcell.UseModelValueAsText = True

Using Code

  1. Define the hyperlink cell by creating an instance of the HyperLinkCellType class.
  2. Be sure to set the size of the cell so that all the text including the hyperlink are visible and display properly.
  3. Specify the text that appears in the cell by specifying the Text property for the HyperLinkCellType object. Specify how much of the text is hyperlink using the LinkAreas property for that object.
  4. Specify the appearance of the hyperlink by setting properties, such as LinkColor.
  5. Assign the hyperlink cell type to a cell or range of cells by setting the CellType property for a cell, column, row, or style to the HyperLinkCellType object.

Example

This example creates a hyperlink cell with multiple links.

C#
Copy Code
fpSpread1.ActiveSheet.Columns[0].Width = 145;
fpSpread1.ActiveSheet.Rows[0].Height = 45;
FarPoint.Win.Spread.CellType.HyperLinkCellType mhp = new FarPoint.Win.Spread.CellType.HyperLinkCellType();
mhp.Text = "Google and Microsoft";
string[] s = new string[]{"www.google.com", "www.microsoft.com"};
mhp.Links = s;
mhp.VisitedLinkColor = Color.Maroon;
LinkArea[] la = new LinkArea[]{new LinkArea(0, 8), new LinkArea(13, 9)};
mhp.LinkAreas = la;
fpSpread1.ActiveSheet.Cells[0, 0].CellType = mhp;
VB
Copy Code
fpSpread1.ActiveSheet.Columns(0).Width = 145
fpSpread1.ActiveSheet.Rows(0).Height = 45
Dim mhp As New FarPoint.Win.Spread.CellType.HyperLinkCellType
mhp.Text = "Google and Microsoft"
Dim s() As String = New String() {"www.google.com", "www.microsoft.com"}
mhp.Links = s
mhp.VisitedLinkColor = Color.Maroon
Dim la() As LinkArea = New LinkArea() {New LinkArea(0, 8), New LinkArea(13, 9)}
mhp.LinkAreas = la
fpSpread1.ActiveSheet.Cells(0, 0).CellType = mhp

Using the Spread Designer

  1. Select the cell or cells in the work area.
  2. In the property list, in the Misc category, select CellType. From the drop-down list, choose the HyperLink cell type. Now expand the CellType property and various properties are available that are specific to this cell type. Select and set those properties as needed.

    Or right-click on the cell or cells and select Cell Type. From the list, select HyperLink. In the CellType editor, set the properties you need. Click Apply. If you create multiple hyper links then make sure the text is set as well. Note that if you were to create the previous code sample in the designer then the text would need to contain 23 characters since the second link starts at 13 and continues for 9 characters. The text is zero based.

  3. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
See Also