Title: Changing Complete Column Or Row Colour in MS FlexGrig Control.
Description: Changes a whole row or columns colour in a FlexGrid control.
Feature List: N/A
Screen-shots: None
Author Name: Ryan Jones
System Requirements: Any - Tested in Win 98, ME, 2000.
License Info: Any - use and modify as you like.

VB Code:
  1. Public Sub FlexGridColumnColor(FlexGrid As MSFlexGrid, ByVal lngColumn As Long, ByVal lngColor As Long)
  2.     Dim lngPrevCol As Long
  3.     Dim lngPrevColSel As Long
  4.     Dim lngPrevRow As Long
  5.     Dim lngPrevRowSel As Long
  6.     Dim lngPrevFillStyle As Long
  7.     If lngColumn > FlexGrid.Cols - 1 Then
  8.         Exit Sub
  9.     End If
  10.     lngPrevCol = FlexGrid.Col
  11.     lngPrevRow = FlexGrid.Row
  12.     lngPrevColSel = FlexGrid.ColSel
  13.     lngPrevRowSel = FlexGrid.RowSel
  14.     lngPrevFillStyle = FlexGrid.FillStyle
  15.     FlexGrid.Col = lngColumn
  16.     FlexGrid.Row = FlexGrid.FixedRows
  17.     FlexGrid.ColSel = lngColumn
  18.     FlexGrid.RowSel = FlexGrid.Rows - 1
  19.     FlexGrid.FillStyle = flexFillRepeat
  20.     FlexGrid.CellBackColor = lngColor
  21.     FlexGrid.Col = lngPrevCol
  22.     FlexGrid.Row = lngPrevRow
  23.     FlexGrid.ColSel = lngPrevColSel
  24.     FlexGrid.RowSel = lngPrevRowSel
  25.     FlexGrid.FillStyle = lngPrevFillStyle
  26. End Sub
  27.  
  28. Public Sub FlexGridRowColor(FlexGrid As MSFlexGrid, ByVal lngRow As Long, ByVal lngColor As Long)
  29.     Dim lngPrevCol As Long
  30.     Dim lngPrevColSel As Long
  31.     Dim lngPrevRow As Long
  32.     Dim lngPrevRowSel As Long
  33.     Dim lngPrevFillStyle As Long
  34.     If lngRow > FlexGrid.Rows - 1 Then
  35.         Exit Sub
  36.     End If
  37.     lngPrevCol = FlexGrid.Col
  38.     lngPrevRow = FlexGrid.Row
  39.     lngPrevColSel = FlexGrid.ColSel
  40.     lngPrevRowSel = FlexGrid.RowSel
  41.     lngPrevFillStyle = FlexGrid.FillStyle
  42.     FlexGrid.Col = FlexGrid.FixedCols
  43.     FlexGrid.Row = lngRow
  44.     FlexGrid.ColSel = FlexGrid.Cols - 1
  45.     FlexGrid.RowSel = lngRow
  46.     FlexGrid.FillStyle = flexFillRepeat
  47.     FlexGrid.CellBackColor = lngColor
  48.     FlexGrid.Col = lngPrevCol
  49.     FlexGrid.Row = lngPrevRow
  50.     FlexGrid.ColSel = lngPrevColSel
  51.     FlexGrid.RowSel = lngPrevRowSel
  52.     FlexGrid.FillStyle = lngPrevFillStyle
  53. End Sub

Example:

VB Code:
  1. Call FlexGridColumnColor(MSFlexGrid, 2, vbRed)
  2. Call FlexGridRowColor(MSFlexGrid, 3, vbBlue)

Hope that helps someone

Cheers,

RyanJ