Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Copper Elite Contributor
Posts: 72
Registered: ‎04-01-2009
Accepted Solution

Change row color in datagrid based on a certain value in one of the columns

Hi all.

 

I have a datagrid where various columns, one specific column is STATUS. I want to be able to change the color of the fields in the entire row (let's say to red) for rows who have the STATUS field equal to INACTIVE.

 

How can I do this?

 

Thank you in advance!

 

SLX LAN v7.2.1

Silver Super Contributor
Posts: 801
Registered: ‎03-24-2009

Re: Change row color in datagrid based on a certain value in one of the columns

Here you go. Check comments on what to change etc.

 

================
Colouring a grid
================

For the Grid - select the property "OnCustomDrawCell" - this will create a sub based on the name of the grid followed by CustomDrawCell e.g.
--------------|-------------|
Sub dgServicesCustomDrawCell(Sender, ByRef Node, ByRef Column, IsSelected, IsFocused, ByRef Text, ByRef Color, ByRef Alignment, ByRef Font, ByRef FontColor)

    Dim sFieldName
    Dim vStatus
    Dim lColumnIndex

    sFieldName = UCase ( Column.FieldName ) ' Field you want to look for

    Select Case sFieldName
        Case "A2_STATUS"   ' ALIAS name of the column in QB
            lColumnIndex = GetColumnIndexByFieldName ( dgServices,"A2_STATUS" ) ' Used so that grid can be sorted/grouped
            vStatus = Node.Values ( lColumnIndex ) ' Gets the actual value
    End Select

    If Not IsNull ( vStatus ) Then   ' Ensure you check for Nulls

        Select Case vStatus
                 Case "Open"
                    FontColor = &H00000000  ' in v7.x - you can use enum of clBlack, clGreen etc
                 Case "Lost"
                    FontColor = &H000000FF
                 Case "Won"
                    FontColor = &H00800000
                    Font.Bold = True
        End Select
    End If

End Sub

'==========================================================================================
Function GetColumnIndexByFieldName ( ByRef Grid, ByVal FieldName )
    Dim i
    Dim lColumnIndex

    lColumnIndex = -1
    For i = 0 To Grid.Columns.Count - 1
        If UCase ( Grid.Columns(i).FieldName ) = UCase ( FieldName ) Then
            lColumnIndex = i
            Exit For
        End If
    Next
    GetColumnIndexByFieldName = lColumnIndex
End Function

 

 

Copper Elite Contributor
Posts: 72
Registered: ‎04-01-2009

Re: Change row color in datagrid based on a certain value in one of the columns

Thanks Mike!
Tuned Listener
Posts: 18
Registered: ‎04-28-2009

Re: Change row color in datagrid based on a certain value in one of the columns

Mike,

is it possible to apply the same method to a code that is built in Code.  Opportunity products for example.  I am using SLX lan version 7.2

thanks much

Mark

Highlighted
Tuned Listener
Posts: 18
Registered: ‎04-28-2009

Re: Change row color in datagrid based on a certain value in one of the columns

i got it,  ID-TEN-T error

Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: Change row color in datagrid based on a certain value in one of the columns

Yes you can. don't forget that you are dealing with visible Nodes, not the Columns, when colouring. Different animals.

RJ Samp
mar
New Member
Posts: 46
Registered: ‎01-11-2010

Re: Change row color in datagrid based on a certain value in one of the columns

I was able to make this work but it only changes the color of the one field. How can we get it to color the entire row?
Thanks!
Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: Change row color in datagrid based on a certain value in one of the columns

color each node in the row.

RJ Samp