View RSS Feed

Development Team Blog

Changing Fonts of the new CJ Grid control

Rate this Entry
The new Visual DataFlex grid classes in Visual DataFlex 16.0 (cCJGrid, cDbCJGrid, etc) do not expose an interface for setting the grid control's various Fonts. This turned out to be beyond the scope for the VDF 16.0 project, however it is still possible to set all of the control's fonts via the COM interface.

For example here is how you can modify the default Font used to display data in the Grid's cells: You would write the following event handler in your grid object...

Code:
Procedure OnCreateGridControl
    Handle hoFont hoPaintManager
    Variant vFont
    Forward Send OnCreateGridControl  
    
    Get phoReportPaintManager to hoPaintManager   // get a handle to the paint manager
    Get Create (RefClass(cComStdFont)) to hoFont  // create a font object
    Get ComTextFont of hoPaintManager to vFont    // bind the font object to the Grid's text font
    Set pvComObject of hoFont to vFont
    
    // set the desired font properties.... 
    Set ComName of hoFont to "Arial"
    Set ComSize of hoFont to 9
    
    Send Destroy to hoFont  // destroy the font object (releases memory)
End_Procedure
The grid's Paint Manager controls one other Font. That is the font used by default in the column headers (caption). This is controlled by the Paint Manager's ComCaptionFont property. To change this font in addition to the text font you would modify the above code as follows...

Code:
Procedure OnCreateGridControl
    Handle hoFont hoPaintManager
    Variant vFont
    Forward Send OnCreateGridControl  
    
    Get phoReportPaintManager to hoPaintManager   // get a handle to the paint manager
    Get Create (RefClass(cComStdFont)) to hoFont  // create a font object
    Get ComTextFont of hoPaintManager to vFont    // bind the font object to the Grid's text font
    Set pvComObject of hoFont to vFont
    
    // set the desired font properties.... 
    Set ComName of hoFont to "Arial"
    Set ComSize of hoFont to 9

    // Change the caption font...
    Get ComCaptionFont of hoPaintManager to vFont    // bind the font object to the Grid's caption font
    Set pvComObject of hoFont to vFont
     
    // set the desired font properties.... 
    Set ComName of hoFont to "Courier New"   // yuck!
    Set ComSize of hoFont to 9
     
    Send Destroy to hoFont  // destroy the font object (releases memory)
End_Procedure
ComCaptionFont also controls the column footer's default font. The footer font can also be individually changed for each column. You would use the column object's ComFooterFont property to perform this. For example you could write the following code in a column object...

Code:
Procedure OnCreateColumn
    Handle hoFont
    Variant vFont
    Forward Send OnCreateColumn
   
    Get Create (RefClass(cComStdFont)) to hoFont  // create a font object
    Get ComFooterFont to vFont  // bind the font object to the column's footer font
    Set pvComObject of hoFont to vFont
   
    // set the desired font properties....
    Set ComName of hoFont to "Arial"
    Set ComSize of hoFont to 9

    Send Destroy to hoFont  // destroy the font object (releases memory)
End_Procedure
As far as I know there is no property to set an individual column's header (caption) font.

Lastly, there is a mechanizim we have exposed in the column object that allow you to set different font attributes for each cell in the column. This is done by augmenting the column's OnSetDisplayMetrics event. This event would let you do something like test the value of a cell and change the font to bold if the value is > 1000 or something. Or you could change the color, or even the font size or typeface. This mechanizim will be fully documented in the help under the OnSetDisplayMetrics.
Categories
Uncategorized

Comments

  1. ivankaupa's Avatar
    Great! Great! I loved it.