
05-27-2009 07:04 AM
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
Solved! Go to Solution.
05-27-2009 07:09 AM
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
05-27-2009 08:30 AM
07-08-2011 12:13 PM
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
07-08-2011 12:44 PM
i got it, ID-TEN-T error
07-12-2011 07:26 AM
Yes you can. don't forget that you are dealing with visible Nodes, not the Columns, when colouring. Different animals.
04-02-2012 02:42 PM
04-02-2012 05:44 PM
color each node in the row.