ComponentOne List 8.0 for ActiveX
Displaying foreground pictures

You can use foreground pictures to add visual cues to static list elements such as caption bars, column headers, and column footers. For example, suppose that you want to sort a column when the user clicks its header, then reverse the sort order when the user clicks it again. If you define two distinct styles for the ascending and descending states, you can easily apply the correct style in the handler for the HeadClick event.

At design time, use the Style Factory property page to create the new styles as follows:

  1. Select the Heading style in the property tree to ensure that new styles will inherit from it. (If you forget this step, you can still change the Parent property of the new style after it is created.)

  2. Enter the name Ascending in the New Style Name text box, then click the New button.

  3. Select and expand the Ascending item at the bottom of the property tree, then set the ForegroundPicture property to an appropriate bitmap, as shown in the following figure.

  4. Depending upon the bitmap used, you may also want to set the TransparentForegroundPicture property to True to ensure that the bitmap displays properly regardless of the heading background color. If this property is True, then the color of the pixel at the lower left corner of the bitmap is used as the transparent color.

  5. Repeat the procedure for the Descending style.

    Or, you can create the Ascending style in code as follows:

    Example Title
    Copy Code
    Dim S As TrueDBList80.Style
    
    Set S = TDBList1.Styles.Add("Ascending")
    
    S.Parent = "Heading"
    
    S.ForegroundPicture = LoadPicture("atoz.bmp")
    
    S.ForegroundPicturePosition = dblFPRightOfText
    
    S.TransparentForegroundPicture = True
    

Note that this example also sets the ForegroundPicturePositionproperty so that the bitmap appears after the column header text. By default, the foreground picture is displayed at the left edge of the column header. The relative placement of the bitmap is also affected by the setting of the column's Alignmentproperty, as shown in the following list.

To apply a style to a column header, set its HeadingStyleproperty to the name of the desired style. You can also examine the string returned by this property in code to determine which style is in effect. The following code illustrates how to implement a handler for the HeadClickevent that inverts the sort order and updates the heading style accordingly:

Example Title
Copy Code
Private Sub TDBList1_HeadClick(ByVal ColIndex As Integer)

    If ColIndex <> 1 Then Exit Sub

 

    Dim SQL As String

    SQL = "select * from composer order by last"

 

    With TDBList1.Columns(1)

        If .HeadingStyle = "Ascending" Then

           .HeadingStyle = "Descending"

           SQL = SQL & " desc"

        Else

           .HeadingStyle = "Ascending"

        End If

    End With

 

    Data1.RecordSource = SQL

    Data1.Refresh

End Sub

The first time the user clicks column 1, its HeadingStyleproperty is set to Ascending, and the foreground bitmap associated with this style appears to the right of the text within the column header. Note that you may have to adjust the HeadLinesproperty at design time to accommodate the height of the bitmap.

The next time the user clicks column 1, its HeadingStyle property is set to Descending, and the bitmap within the column header is changed accordingly.

Since foreground pictures are components of Style objects, they are not restricted to static elements such as column headers—they can also be displayed within data cells. For example, you can use the AddRegexCellStyle method to attach a picture to cells that satisfy certain criteria:

Example Title
Copy Code
Dim S As New TrueDBList80.Style

S.ForegroundPicture = LoadPicture("bach.bmp")

S.ForegroundPicturePosition = dblFPRight

TDBList1.Columns(1).AddRegexCellStyle dblAllCells, S, "Bach"

Note the similarity between this example and the one presented earlier in Applying cell styles by contents. The only difference is that this code sets picture properties instead of font properties, resulting in the following display.

You can also use the FetchCellStyle event to assign a foreground picture to a cell:

Example Title
Copy Code
Private Sub TDBList1_FetchCellStyle( _

        ByVal Condition As Integer, _

        ByVal Split As Integer, _

        Bookmark As Variant, _

        ByVal Col As Integer, _

        ByVal CellStyle As TrueDBList80.StyleDisp)

 

If Col <> 1 Then Exit Sub

If TDBList1.Columns(1).CellText(Bookmark) = "Bach" Then

    CellStyle.ForegroundPicture = LoadPicture("bach.bmp")

    CellStyle.ForegroundPicturePosition = dblFPRight

End If

End Sub

Prior to version 6.0, the only way to display a bitmap within a data cell was to specify a text-to-picture translation using the ValueItems collection. Although this technique was adequate for a limited set of known data values, it did not support the display of arbitrary bitmaps. Fortunately, version 8.0 overcomes this limitation. Tutorial 18 demonstrates how to use styles to display arbitrary bitmaps within data cells.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback