View Single Post
 
Old 08-16-2004, 10:56 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,164
Default The power of the FillStyle property and a cell replacement function.

Using the FillStyle property you can change a range of cells with a single command.
But you always have to take care about the current selected row, col, rowsel and colsel properties.
That's why I wrote a generic function which is capable of changing most of the cell properties with a single command.
Code:
Option Explicit Private Enum FGCellStyle fgcsBackColor = 1 fgcsForeColor = 2 fgcsText = 3 fgcsTextStyle = 4 fgcsFontName = 5 fgcsFontBold = 6 fgcsFontItalic = 7 fgcsAllignment = 8 End Enum Private Sub Form_Load() With MSFlexGrid1 .Cols = 10 .Rows = 10 End With FG_Cell MSFlexGrid1, fgcsBackColor, 1, 1, 7, 7, RGB(191, 191, 255) FG_Cell MSFlexGrid1, fgcsBackColor, 3, 2, 7, 5, vbGreen FG_Cell MSFlexGrid1, fgcsForeColor, 1, 4, 3, 6, vbRed FG_Cell MSFlexGrid1, fgcsText, 1, 1, 5, 5, "Hello" FG_Cell MSFlexGrid1, fgcsFontBold, 2, 3, 5, 6, True FG_Cell MSFlexGrid1, fgcsAllignment, 2, 4, 3, 4, flexAlignRightCenter FG_Cell MSFlexGrid1, fgcsFontName, 1, 3, 2, 5, "Arial" FG_Cell MSFlexGrid1, fgcsTextStyle, 1, 1, 3, 3, flexTextRaised End Sub Private Sub FG_Cell(FG As MSFlexGrid, ByVal What As FGCellStyle, Row1 As Long, Col1 As Long, Row2 As Long, Col2 As Long, Value As Variant) Dim PrevRowCol(3) As Long ' to store the actual settings Dim PrevFillStyle As Integer ' to store the actual settings With FG .Redraw = False ' Store current settings PrevRowCol(0) = .Row PrevRowCol(1) = .Col PrevRowCol(2) = .RowSel PrevRowCol(3) = .ColSel PrevFillStyle = .FillStyle ' Set the range .FillStyle = flexFillRepeat .Row = Row1 .Col = Col1 .RowSel = Row2 .ColSel = Col2 ' Apply changes Select Case What Case fgcsBackColor .CellBackColor = Value Case fgcsForeColor .CellForeColor = Value Case fgcsText .Text = Value Case fgcsTextStyle .CellTextStyle = Value Case fgcsFontName .CellFontName = Value Case fgcsFontBold .CellFontBold = Value Case fgcsFontItalic .CellFontItalic = Value Case fgcsAllignment .CellAlignment = Value End Select ' Restore settings .FillStyle = PrevFillStyle .Row = PrevRowCol(0) .Col = PrevRowCol(1) .RowSel = PrevRowCol(2) .ColSel = PrevRowCol(3) .Redraw = True End With End Sub
Attached Images
File Type: gif cellstyles.gif (9.9 KB, 563 views)
Reply With Quote