ComponentOne List 8.0 for ActiveX
Tutorial 18 - Displaying Arbitrary Bitmaps

In this tutorial, you will learn how to use Style objects to display arbitrary bitmaps within list cells. In addition to font, color, and alignment settings, Style objects support both background and foreground pictures. Background pictures can be centered, tiled, or stretched to fill the entire cell. Foreground pictures can be positioned relative to the cell text, and can also be displayed using a transparent color.

  1. Start a new project.

  2. Place a True DBList control (TDBList1), a command button (Command1), and a TextBox control (Text1) on the form (Form1).

  3. Set the DataMode property of TDBList1 to 4 - Storage (the default value of this property is 0 - Bound).

  4. Right-click TDBList1 to display its context menu and choose Properties to display the Property Pages dialog box.

  5. Click on the RowHeight property on the General Properties page, and enter the desired row height.

  6. Select the Columns property page by clicking the Columns tab. Set the Caption property of Columns(00) and Columns(01) to Picture and File Name, respectively.

  7. Select the Style Factory property page by clicking the Style Factory tab. Expand the Normal style and change its VerticalAlignment property from 0 - Top to 2 - Vertical Center. This will ensure that the text and pictures are vertically centered in each row.

  8. Set the Caption (Visual Basic) property of Command1 to Display. Your form should now look like this:

    Adding XArrayDB to the project

    As in Tutorial 19, we will use the XArrayDB object; therefore, we need to add its reference to the project.

  9. Select References from the Project menu to display a list of available type library references. Select the check box labeled ComponentOne XArrayDB Object (XARRAYDB.OCX), and then press the OK button.

  10. Enter the path of the \Bitmaps\Flags directory in the Text property of Text1.

  11. Add the following declaration to the General section of Form1:

    Example Title
    Copy Code
    Dim x As New XArrayDB
    
  12. Enter the following code in the Form_Load (Visual Basic) event:

    Example Title
    Copy Code
    Private Sub Form_Load()
    
    ' Initially we resize the XArrayDB
    
    ' to 0 rows and 2 columns
    
        x.ReDim 0, -1, 0, 1
    
        Set TDBList1.Array = x
    
       
    
    ' Enable FetchCellStyle Event
    
        TDBList1.Columns(0).FetchStyle = True
    
    End Sub
    
  13. Add the following code to the Click (Visual Basic) event of Command1:

    Example Title
    Copy Code
    Private Sub Command1_Click()
    
        Dim s As String
    
        Dim i As Integer
    
       
    
        x.ReDim 0, -1, 0, 1
    
      
    
        i = 0
    
       
    
    ' Fill the XArrayDB object with all bitmap
    
    ' file names found in this directory
    
        s = Dir(Text1.Text & "\*.bmp")
    
       
    
        While s <> ""
    
            If s <> "." And s <> ".." Then
    
                x.ReDim 0, x.UpperBound(1) + 1, 0, 1
    
                x(i, 1) = s
    
                i = i + 1
    
            End If
    
            s = Dir
    
        Wend
    
       
    
    ' Reinitialize the list
    
        TDBList1.Bookmark = Null
    
        TDBList1.ReBind
    
    End Sub
    
  14. Enter the following code in the FetchCellStyle event:

    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)
    
     
    
        Dim PathFileName As String
    
    ' Full Path file name of a picture
    
        PathFileName = Text1.Text & "\" & _
    
                       TDBList1.Columns(1).CellText(Bookmark)
    
     
    
    ' Load the picture
    
        CellStyle.BackgroundPicture = LoadPicture(PathFileName)
    
    End Sub
    

Run the program and observe the following:

For more information, see Applying Pictures to List Elements.

This concludes Tutorial 18.

 

 


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

Product Support Forum  |  Documentation Feedback