Mike Sabatier Level: Protégé
 Registered: 05-03-2007 Posts: 6
|
Re: MSHFLEXGRID
Hi elgy
A little routine which scans down the grid (hfgGrid) testing if the row number is ODD (the row number MOD 2 <> 0) sets the row colour (CellBackColor) to vbWhite or is EVEN (the row number MOD 2 = 0) sets the row colour(CellBackColor) to vbYellow would do the trick for selected cells.
If you put the code into a routine with parameters, you could call the routine for different grids with different colours or allow the user to select the different colours from, say, a combobox .
Public Sub GridSetAltRowColours(phfgGrid As MSHFlexGrid, plngColour1 As Long, plngColour2 As Long)
'Sets colours of alternate grid rows to specified colours****
'Declare local variables and allocate storage space *******
Dim pintRow As Integer
'Scan grid rows setting colours ************************
With phfgGrid
If .Rows > 1 Then 'Assuming a FIXED header row of labels
.Col = 0 'Select from first column
For pintRow = 1 To .Rows - 1
.Row = pintRow
.ColSel = .Cols - 1 'Select to last column
.FillStyle = flexFillRepeat 'Applies to all selected cells
If pintRow Mod 2 <> 0 Then 'RowNum is Odd
.CellBackColor = plngColour1 'Set first colour
Else
.CellBackColor = plngColour2 'RowNum is Even
End If
Next pintRow
End If
End With
End Sub
The routine could then be called as follows:
'Set alternate row colours in Transactions grid ******
Call GridSetAltRowColours(hfgTrans, vbWhite, vbYellow)
or, say:
'Set alternate row colours in Receipts grid **********
Call GridSetAltRowColours(hfgReceiptss, vbCyan, vbWhite)
This was fun - I hope you like it
|