Flexgrid column font/color

lowfreq
10-09-2001, 12:12 PM
Is there a way to change the color or/and the font of selected cells or ranges of cells?

Banjo
10-09-2001, 12:23 PM
You need to store the select range and then loop through the cells setting the cellbackcolor property:
<pre>Sub ColourSelection(grd As MSFlexGrid, ByVal colour As Long)
Dim colMin As Integer, colMax As Integer
Dim rowMin As Integer, rowMax As Integer
Dim i As Integer, j As Integer

colMin = Min(grd.Col, grd.ColSel)
colMax = Max(grd.Col, grd.ColSel)
rowMin = Min(grd.Row, grd.RowSel)
rowMax = Max(grd.Row, grd.RowSel)

For i = colMin To colMax
For j = rowMin To rowMax
grd.Col = i
grd.Row = j
grd.CellBackColor = colour
Next j
Next i
End Sub

Function Min(X As Long, Y As Long) As Long
If X &gt; Y Then Min = Y Else Min = X
End Function
Function Max(X As Long, Y As Long) As Long
If X &gt; Y Then Max = X Else Max = Y
End Function</pre>

Banjo
10-09-2001, 12:25 PM
You can do exactly the same thing for the CellForeColor, CellFontName, CellFontSize etc. properties.

Laurent
10-09-2001, 12:25 PM
is there something like this for datagrids? i would like to do it by colunm

I'll be amongst the best any minute now !

Banjo
10-09-2001, 12:33 PM
Just remove the bit that takes the current selection and replace it with your own arbitrary cell range.
Of course, I'm assuming that the DataGrid work in much the same way as the FlexGrid. I don't use the DataGrid much.

Laurent
10-09-2001, 12:35 PM
ok i'll play around with it, thanks

I'll be amongst the best any minute now !

BillSoo
10-09-2001, 01:00 PM
I don't use the datagrid much either, but I thought that it was *column* based rather than *cell* based. Which implies that you can change the font/color of a column, but not of an individual cell.

As I said though, I could be mistaken.


"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

Laurent
10-09-2001, 01:18 PM
got an idea how? i tried backcolor, but that's for all the grid, when you go under columns there's no backcolor property???


I'll be amongst the best any minute now !

Banjo
10-09-2001, 01:38 PM
I've just done some searching through MSDN and I couldn't find anything either. Sorry.

Maybe The Hand know some messages that you could intercept.

BillSoo
10-09-2001, 06:02 PM
Sorry.....I mostly use flexgrids, and when I have to use a datagrid, I mostly use the True DBGrid from ComponentOne. So I don't know hardly anything about the normal Datagrid.



"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum