Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, July 5, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Change the font color just for a cell in a datagrid
SLX_Novice
Posts: 246
 
Change the font color just for a cell in a datagridYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Jun 11 11:48 AM
fiogf49gjkf0d

Hi all.


Using SLX LAN v7.2.1.


I have a datagrid that has a field called "Difference". If the value in the "Difference" column < 0 then I want the font color to be red (clred) otherwise keep it black. I've been playing with CustomDrawCell(Sender, ByRef Node, ByRef Column, IsSelected, IsFocused, ByRef Text, ByRef Color, ByRef Alignment, ByRef Font, ByRef FontColor) , but I'm changing the entire row to red instead of the cell. This datagrid will have multiple rows and some will have a difference < 0 and others won't, I just need the cells with difference < 0 to be red.


 


Any ideas?


 


Sub DataGrid1CustomDrawCell(Sender, ByRef Node, ByRef Column, IsSelected, IsFocused, ByRef Text, ByRef Color, ByRef Alignment, ByRef Font, ByRef FontColor)


Dim DiffColumn, DiffCell


Set DiffColumn = Datagrid1.Columns.Item("Difference")
DiffCell = Node.Values(DiffColumn.Index)
If DiffCell < 0 Then
FontColor = clred
Else
FontColor = clblack
End If


End Sub

[Reply][Quote]
Mike Spragg
Posts: 1226
Top 10 forum poster: 1226 posts
 
Re: Change the font color just for a cell in a datagridYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Jun 11 8:04 AM
fiogf49gjkf0d

================
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

[Reply][Quote]
SLX_Novice
Posts: 246
 
Re: Change the font color just for a cell in a datagridYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Jun 11 8:06 AM
fiogf49gjkf0d

Thanks Mike. But I tried that script but that highlights the entire row instead one specific cell.

[Reply][Quote]
Mike Spragg
Posts: 1226
Top 10 forum poster: 1226 posts
 
Re: Change the font color just for a cell in a datagridYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Jun 11 8:07 AM
fiogf49gjkf0d

Nope, it doesn't - look again - it's column based...

[Reply][Quote]
SLX_Novice
Posts: 246
 
Re: Change the font color just for a cell in a datagridYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Jun 11 8:53 AM
fiogf49gjkf0d

Oh ok.


Below is the code, the name of the field is "DIFFERENCE" if it's less than 0 then make the DIFFERENCE cell red otherwise keep it black. When I run this it doesn't do anything:


 


Sub DataGrid1CustomDrawCell(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 ( "Difference" ) ' Field you want to look for


Select Case sFieldName
Case "Difference" ' ALIAS name of the column in QB
lColumnIndex = GetColumnIndexByFieldName ( datagrid1,"Difference" ) ' 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


If vStatus < 0 then
FontColor = clred
Else
FontColor = clblack
End If


End If



End Sub

[Reply][Quote]
Mike Spragg
Posts: 1226
Top 10 forum poster: 1226 posts
 
Re: Change the font color just for a cell in a datagridYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Jun 11 9:02 AM
fiogf49gjkf0d

Difference is the field name - but it's not the alias name. Open the grid, select SQL, hit Display SQL. Find the field difference and find it's alias (most likey a1_difference) - use that in the GetColumnIndexByFieldName

[Reply][Quote]
SLX_Novice
Posts: 246
 
Re: Change the font color just for a cell in a datagridYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 10 Jun 11 9:06 AM
fiogf49gjkf0d

The datagrid is created via code, when I run the Profiler to see the executed SQL I don't see an alias for the field. The field is a calculated field based on 2 other fields.

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 7/5/2025 2:52:46 AM