?
Solved

Separate Font Colors per Row in DataGrid

Posted on 2000-01-27
2
Medium Priority
?
786 Views
Last Modified: 2013-12-26
Is there a way to specify the ForeColor (font color) of a given row in a
datagrid (MS datagrid)?
0
Comment
Question by:hquin
  • 2
2 Comments
 
LVL 6

Expert Comment

by:VBGuru
ID: 2481822
Are you talking of DBGrid?
0
 
LVL 6

Accepted Solution

by:
VBGuru earned 200 total points
ID: 2482112
Use the True DB grid's FetchCellStyle event to do that.
Only pre-requist is that the 1st column is a column with the serial number. This is needed for deciding the color of the row. As shown below.
Private Sub TDBGrid1_FetchCellStyle(ByVal Condition As Integer, ByVal Split As Integer, Bookmark As Variant, ByVal Col As Integer, ByVal CellStyle As TrueDBGrid50.StyleDisp)
   
    ' FetchCellStyle is the event we need to use
    ' to affect the colors of individual cells
    ' based on custom criteria.

    On Error GoTo done:
    Select Case Col
        Case 1
'Assume that the first column contain the serial numbers, Just make thecalucalation of
'Even and odd number and assign the color to the rows.
            Dim N As Long

            N = Val(TDBGrid1.Columns(Col).CellText(Bookmark))
            If (N / 2) = (N \ 2) Then        'If the row is a even or odd
                CellStyle.BackColor = vbGreen
                CellStyle.ForeColor = vbWhite
            Else
                CellStyle.BackColor = vbRed
                CellStyle.ForeColor = vbWhite
            End If
        Case 3
            ' For all customers who     End Select

Exit Sub

done:


End Sub





------------

Note:The FetchCellStyle event occurs when the grid is about to display cell data in a column whose FetchStyle property is set to True.  By setting one or more properties of the Style object passed in the CellStyle parameter, your application can change the appearance of individual cells.


---------------
Syntax      TDBGrid_FetchCellStyle (ByVal Condition As Integer, ByVal Split As Integer, Bookmark As Variant, ByVal Col As Integer, ByVal CellStyle As TrueDBGrid50.StyleDisp)
      TDBDropDown_FetchCellStyle (ByVal Condition As Integer, Bookmark As Variant, ByVal Col As Integer, ByVal CellStyle As TrueDBGrid50.StyleDisp)

Event applies to TDBGrid and TDBDropDown controls.

Arguments      Condition is the sum of one or more CellStyleConstants describing the disposition of the cell being displayed.  

Split is an integer that identifies the split containing the cell being displayed.  This argument is omitted for TDBDropDown controls.

Bookmark is a variant that identifies the row containing the cell being displayed.

Col is an integer that identifies the column containing the cell being displayed.

CellStyle is a Style object used to override the font and color characteristics of the cell being displayed.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question