Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing the font of a particular cell of the grid

Status
Not open for further replies.

shahina

Programmer
Aug 19, 2003
47
IN
Hi..

Is it possible to change the font of a particular cell of the grid? i mean i want to show the data in the grid and should be disabled(in grey color)..how to do it? please help me..thanx in advance..

with regards,
shahina
 
Which Grid?

Data grid - I don't think so.
Flex grid - Set the .col and .row properties to point to the specific cell and then set the .cellforecolor property.

zemp
 
Thank u zemp..how to change the font color of the entire row? thanx in advance..

regards,
shahina.
 
You should be able to do it this way:

Assuming fg is a flexgrid:

fg.col = fg.cols - 1
fg.ColSel = 0
fg.cellforecolor = <your color here>

If this doesn't work, then you will need to loop over all the cells and set them one at a time.



"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
When you are doing what ArtieChoke suggested you will need to set the .fillstyle to flexFillRepeat (or similar, I don't remember it exactly, check the intellisense or object browser). It is also a good idea to set the selected row as well.
Code:
fg.row= x
fg.rowsel=x
fg.col = 0
fg.ColSel = fg.cols - 1
fg.fillsytle=flexfilRepeat
fg.cellforecolor = <your color here>
Basically you are selecting a range of cells, telling the grid to repeat the change for all the cells in the range and then telling the grid what the change is.

If you don't set the filstyle you will need to loop through the cells individually.

ArtieChoke - I think that you got the .col and .colsel assignments switched.


zemp
 
zemp,
I checked help (and a working example of mine) before I posted - when you set col, it resets colsel to that value, so you need to set it afterwards to get the range - doh! :)

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 

Thank u ArtieChoke and Zemp..

when i give the flexfillrepeat, it is getting deleted..i don't know if the font color is changed to white also..if anyother color is selected the result is the same and without flexrepeat, only one cell is getting changed..anyway i got it by puting it in loop..

thank u very much..

regards,
shahina.
 
shahina - You can look at the following threads for some more information. Some other properties may be causing the problem. Like the .Selectionmode property.

thread222-749325
thread222-741717
thread222-668987

ArtieChoke - The way you had originally still worked. Seems that you were selecting the columns from right to left rather than left to right. That's what through me. Also I have never had problems with my assignments, I also set the .colsel after setting the .col. Any way there is more than one way to do things.


zemp
 
Hi everybody,

This is the sub I made some time ago. Put it in the module. Put populated MSHFlexGrid with some number of columns and rows and a command button on the form. In the click event of the button, call this sub as shown in the comments:

Public Sub PaintFlexGridRows(ByRef pobjMsFlexGrid As Control, _
ByVal plngStartColumn As Long, _
ByVal plngStartRow As Long, _
ByVal plngRowsInOneColorBlock As Long, _
ByVal plngFirstBackColor As Long, _
ByVal plngSecondBackColor As Long, _
ByVal plngFirstForeColor As Long, _
ByVal plngSecondForeColor As Long)

'******************************************************************************
' DESCRIPTION: Paints flex grid rows into arbitrary chosen interchangable
' colors (both back and fore colors).
'
' Example:
'
' PaintFlexGridRows MSHFlexGrid1, 1, 1, 3, vbRed, vbWhite, vbGreen, vbYellow
'
'******************************************************************************

On Error Resume Next

Dim lngRow As Long
Dim blnFirstColor As Boolean
Dim lngCurrentColumn As Long
Dim lngCurrentRow As Long
Static lngRowsOnOneColor As Long

With pobjMsFlexGrid

lngCurrentColumn = .Col
lngCurrentRow = .Row

.Col = plngStartColumn
.FillStyle = flexFillRepeat

For lngRow = plngStartRow To .Rows - 1
.Row = lngRow
.ColSel = .Cols - 1
.CellForeColor = IIf(blnFirstColor, plngFirstForeColor, plngSecondForeColor)
.CellBackColor = IIf(blnFirstColor, plngFirstBackColor, plngSecondBackColor)

lngRowsOnOneColor = lngRowsOnOneColor + 1
If lngRowsOnOneColor > plngRowsInOneColorBlock - 1 Then
lngRowsOnOneColor = 0
blnFirstColor = Not blnFirstColor
End If
Next lngRow

.Col = lngCurrentColumn
.Row = lngCurrentRow

End With

End Sub

Vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top