Change Font color in GridView
Posted
#1
(In Topic #2046)
Enthusiast

How can I change a colums font color
Hello all,I hope someone smarter then myself can help.
I am using the following code to change the background of a Column as needed
Code
If TotalOfDay > 0 Then
If TotalOfDay > global.TotalDailyTarget Then
frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.green
Else If TotalOfDay = global.TotalDailyTarget Then
frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.Orange
Else If TotalOfDay >= AllowedGapValue And TotalOfDay <= global.TotalDailyTarget Then
frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.Yellow
Else
frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.red
End If
Else
frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.white
End If
if someone would be as kind to show me how I can change the font color I would be most greatful.
Kind Regards
Andy
Posted
Expert


Does the format
Gridview[RowNo , ColumnNo].Foreground = Color.Red
not work ?
This works for me with Gambas 3.21.3 on Linux Mint 22.3
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Guru


Run the code in a Graphical Application. I hope it helps.
Code (gambas)
- .Padding = 5
- .Arrangement = Arrange.Vertical
- .Height = 525
- .Width = 375
- .Center
- .Rows.Count = 25
- .Columns.Count = 6
- Gridview1.Columns[iCol].Background = iBack[iCol]
- .Alignment = Align.Center
- .Foreground = Color(Rand(0, 255), Rand(0, 255), Rand(0, 255))
Posted
Enthusiast

Quincunxian said
Hi Andy.
Does the format
Gridview[RowNo , ColumnNo].Foreground = Color.Red
not work ?
![]()
This works for me with Gambas 3.21.3 on Linux Mint 22.3
From “Post #14,213”, February 21st 2026, 6:13 PM
Hi Quincunxian
I am still using 3.19.5 as I have not worked out yet how to update the Database funtions to the new version that 3.2X uses so I do not have access to the .foreground option
Posted
Administrator

I'm still on 3.18.0 and it works for me. I created a reminder calendar that's still running strong after 10 years that uses .Foreground, .Background, .Font.Size, .Text, .Alignment extensively - all without issue.
This is just one way I use .Background in my project to get it's data from a settings file.
gvCalendar[iRow, iCol].Background = MGlobal.hSetting["System/Calendar/Reminder", &H00FFFF&] ' add color to reminder days
sholzy
Gambas One Site Director
To help make creating posts and using the forum a little easier:
Tutorials - Website and forum and Playground
To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Gambas One Site Director
To help make creating posts and using the forum a little easier:
Tutorials - Website and forum and Playground
To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Posted
Enthusiast

That is really stange when I do use the .Foreground I get a error saying "Unkown Symbol 'Foreground' in class '_GridView_Column'sholzy said
Unless something changed for 3.19.5 it should be working.
I'm still on 3.18.0 and it works for me. I created a reminder calendar that's still running strong after 10 years that uses .Foreground, .Background, .Font.Size, .Text, .Alignment extensively - all without issue.
This is just one way I use .Background in my project to get it's data from a settings file.gvCalendar[iRow, iCol].Background = MGlobal.hSetting["System/Calendar/Reminder", &H00FFFF&] ' add color to reminder days
From “Post #14,217”, February 22nd 2026, 12:49 PM
This is what I am using to create my gridview
Code (gambas)
- With frmDashBoard.GridViewSaleSummary
- .Columns.Count = 4
- .Columns[0].Width = 100 'Current Week
- .Columns[1].Width = 100 'Last Week
- .Columns[0].Alignment = Align.BottomLeft 'Current Day Figures
- .Columns[1].Alignment = Align.BottomLeft 'Day 2
- .Rows[0].Text = "Customer Count"
- .Rows[1].Text = " Sales Figures"
- .Rows[2].Text = " Refund Figures"
- .Rows[3].Text = " TOTAL(s)"
- .Columns[0].Text = "Last Week"
- .Columns[1].Text = "Current Week"
- .SetFocus
and then I call this code
Code (gambas)
- frmDashBoard.GridViewLast7Days[1, (i - 1)].Text = global.FormatCurrency(TotalOfDay_Sales, "Plus")
- frmDashBoard.GridViewLast7Days[1, (i - 1)].Alignment = Align.BottomRight 'show Refund
- frmDashBoard.GridViewLast7Days[2, (i - 1)].Text = global.FormatCurrency(TotalOfDay_Refunds, "Plus")
- frmDashBoard.GridViewLast7Days[2, (i - 1)].Alignment = Align.BottomRight 'Total for the day
- frmDashBoard.GridViewLast7Days[3, (i - 1)].Text = global.FormatCurrency(TotalOfDay, "Plus")
- frmDashBoard.GridViewLast7Days[3, (i - 1)].Alignment = Align.BottomRight
- frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.Orange
- frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.Black
- frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.Yellow
- frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.Black
- frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.white
- frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.Black
So what could I be doing wrong?
[reason for edit: cleaned up code to display better. second code block's indentation isn't correct.)
Last edit: by sholzy
Posted
Administrator



You must be doing something wrong and the fact that you post your code in one long line doesn't really help.
If you post code and disabled WYSIWYG, you need to add '<br>' to the end of all your lines of code or else you get what you did, one long unreadble line with a for next loop.
I hope this help
Edit:
I see you where talking about the Foreground and not the Backgound. My mistake.
GridView.Columns has no Foreground property, so don't even bother trying.
And GridView[0].Background = Color.Yellow works on Column level and will make ALL cells in Column 0 (first one) yellow.
Is that what you want? Example code and result screen below.


Foreground needs to be done on cell level with the GridView[iRon, iCol].
Background can be done in the same manner.
Do you use the Gridview_Data event to populate your GridView or do you use your own code loops? Just wondering.
Last edit: by gbWilly
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Enthusiast

gbWilly said
Since Gambas 3.1
You must be doing something wrong and the fact that you post your code in one long line doesn't really help.
If you post code and disabled WYSIWYG, you need to add '<br>' to the end of all your lines of code or else you get what you did, one long unreadble line with a for next loop.
I hope this help
Edit:
I see you where talking about the Foreground and not the Backgound. My mistake.
GridView.Columns has no Foreground property, so don't even bother trying.
And GridView[0].Background = Color.Yellow works on Column level and will make ALL cells in Column 0 (first one) yellow.
Is that what you want? Example code and result screen below.
Foreground needs to be done on cell level with the GridView[iRon, iCol].
Background can be done in the same manner.
Do you use the Gridview_Data event to populate your GridView or do you use your own code loops? Just wondering.
From “Post #14,234”, February 23rd 2026, 9:48 AM
I am using loops to populate the grid
so would frmDashBoard.GridViewLast7Days.Row[(i - 1)].Foreground = Color.Black work or am i on a copmpletely wrong trail of thought?
Also sorry about the code thing I am still getting use to the new website
Posted
Administrator



AndyGable said
I am using loops to populate the grid
so would frmDashBoard.GridViewLast7Days.Row[(i - 1)].Foreground = Color.Black work or am i on a completely wrong trail of thought?
From “Post #14,235”, February 23rd 2026, 11:10 AM
If you type the last dot in frmDashBoard.GridViewLast7Days.Row[(i - 1)]. does the autocomplete with properties pop up (like in my earlier screenshot on Background)?
If not, then it probably can't be done. simple as that.
You need to set the Foreground at a cell by cell basis what should be easy in 2 For Next loops, one for colum index (fields) and one for the row index (records)
frmDashBoard.GridViewLast7Days[iRow, iCol].Foreground = Color.Red will work for the cell in row iRow and column iCol. There is your solution.
It has all been demonstarted to you above exstensively. Did you take time to study and comprehend what was shown and explained to you (source package included to test).
I ask because you try to do other things than have been demonstrated and explained.
Quin posted: Gridview[RowNo , ColumnNo].Foreground = Color.Red
cogier posted: GridView1[iRow, iCol].Foreground + source archive to test and play for understanding the matter
You do: GridView.Columns[(i Row].Foreground =
you posted: So what could I be doing wrong?
gbWilly answerd: Foreground needs to be done on cell level with the GridView[iRow iCol].
You do: GridView.Row[(iCol)].Foreground =
You ask: will above work or am i on a completely wrong trail of though
my answer: You either, don't read what has been answerd OR you don't understand what you read, as the answer has been given multiple times over, yet you try something else, that nobody here advised
Enjoy…
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Administrator

Code (gambas)
- hCurrentDayColor = New Border
- With hCurrentDayColor 'specify cell border
- .Width = SpinBox3.Value
- .Color = ColorButton5.Value
- gridviewPreview.Columns.Count = 1
- gridviewPreview.Rows.Count = 1
- gridviewPreview.Columns.Width = 65
- gridviewPreview.Rows.Height = 86
- gridviewPreview[0, 0].Border = hCurrentDayColor
- gridviewPreview[0, 0].Background = ColorButton6.Value
calendar_config.png
calendar_config_live.png
This code builds the calendar and sets the background color for the day where there is an entry. The code also sets a border color around the current day. The original version would change background colors depending on how close to the day the event is. These colors are set in the config panel and saved to a settings file.
Startin on line 78 is the code that does most of the work.
Code (gambas)
- hCurrentDayBorder = New Border
- With hCurrentDayBorder 'specify cell border
- .Width = MGlobal.hSetting["System/Calendar/CurrentDay/Border", 5]
- .Color = MGlobal.hSetting["System/Calendar/CurrentDay/Color", &HFFFFBF&]
- gvCalendar.Clear
- iY = sbYear.Value
- iM = cmbMonth.Index
- iCount = MGlobal.hResData!Number
- ' the next 2 lines preserve our original year and month values from the combo
- ' and spin boxes for use in our "days to month" map below
- iMm = iM
- iYy = iY
- ' map combo and spinbox values to Zeller's Rule formula.
- ' March becomes 1 st month, and Jan/Feb become 11/12 respectively.
- iMm -= 2 ' subtract 2 from the combobox value. this aligns months 1 - 10 with the rule.
- iMm += 12
- iYy -= 1 ' Jan/Feb months need 1 subtracted from the year for the rule to work.
- iDays = 31
- iDays = 30
- Case 2
- iQ = 1 ' sets which day of month we want to find the day of week for.
- iJ = Floor(iYy / 100) ' extract 2 digit year
- iH = (iQ + (Floor((13 * iMm - 1) / 5)) + iK + (Floor(iK / 4)) + Floor(iJ / 4) + (5 * iJ)) ' Zeller's Rule
- ' create the calendar
- iRow = 0
- iCol = iH
- ' this sets the number of rows needed for the number of days in the month.
- ' a few months require an extra row when the month starts on a thursday, friday, or saturday and has > 29 days.
- ' db.Debug = True
- gvCalendar[iRow, iCol].Text = i
- gvCalendar[iRow, iCol].Alignment = Align.TopLeft
- gvCalendar[iRow, iCol].Background = &HFFFFFF& ' clear all cells of color
- ' If i = Day(Now) Then gvCalendar[iRow, iCol].Background = MGlobal.hSetting["System/Calendar/CurrentDay/Color", &HFFFFBF&] ' add color to today's date
- iEnd = iStart + 86400
- MGlobal.hResData = MGlobal.hDB.Exec("SELECT * FROM schedule WHERE date > &1 AND date < &2", iStart, iEnd)
- gvCalendar[iRow, iCol].Background = MGlobal.hSetting["System/Calendar/Reminder", &H00FFFF&] ' add color to reminder days
- Inc iCol
- iCol = 0 ' reset the column count to 0, and...
- iRow += 1 ' increment the row count.
- ' db.Debug = False
calendar.png
(If I remember correctly gbWilly helped with figuring out a few things with the functionality of the calendar.
sholzy
Gambas One Site Director
To help make creating posts and using the forum a little easier:
Tutorials - Website and forum and Playground
To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Gambas One Site Director
To help make creating posts and using the forum a little easier:
Tutorials - Website and forum and Playground
To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Posted
Administrator

AndyGable said
Also sorry about the code thing I am still getting use to the new website
From “Post #14,235”, February 23rd 2026, 11:10 AM
No worries. I'll see what I can do to clean up your post to display the code better.
As gbWilly said, disabling the WYSIWYG editor makes life a little easier for posting code.
If you're not sure how to disable the WYSIWYG editor, and you haven't seen the tutorials forum, there are a few tutorials that might help to make posting a little easier. Editors, Post Templates, Gambas Code Syntax Highlighting. There is also a Playground if you're feeling adventurous and want to test out the different functions of the editor.
sholzy
Gambas One Site Director
To help make creating posts and using the forum a little easier:
Tutorials - Website and forum and Playground
To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Gambas One Site Director
To help make creating posts and using the forum a little easier:
Tutorials - Website and forum and Playground
To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Posted
Administrator



Seeing the names of several of the variable names used (my trade mark so to speak) and the approach method, I would say you are correct, even if I don't remember anymore, must have been at least 10 plus years back in timesholzy said
(If I remember correctly gbWilly helped with figuring out a few things with the functionality of the calendar.)
From “Post #14,237”, February 23rd 2026, 2:18 PM
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Administrator

gbWilly said
Seeing the names of several of the variable names used (my trade mark so to speak) and the approach method, I would say you are correct, even if I don't remember anymore, must have been at least 10 plus years back in timesholzy said
(If I remember correctly gbWilly helped with figuring out a few things with the functionality of the calendar.)
From “Post #14,237”, February 23rd 2026, 2:18 PM
From “Post #14,239”, February 23rd 2026, 3:25 PM
Looking at the build logs… the first build was May 4, 2016. 10 year anniversary coming up!
sholzy
Gambas One Site Director
To help make creating posts and using the forum a little easier:
Tutorials - Website and forum and Playground
To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Gambas One Site Director
To help make creating posts and using the forum a little easier:
Tutorials - Website and forum and Playground
To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Posted
Guru


There has been a lot said about your issue, but the simple point is that the only way to change the Foreground is to do it on a cell by cell basis.AndyGable said
so would frmDashBoard.GridViewLast7Days.Row[(i - 1)].Foreground = Color.Black work or am i on a copmpletely wrong trail of thought?
Have a look at my revised code that changes the Column Foreground using the Sub Routine ChangeColumnForeground.
Code (gambas)
- ' Gambas class file
- .Padding = 5
- .Arrangement = Arrange.Vertical
- .Height = 525
- .Width = 375
- .Center
- .Rows.Count = 25
- .Columns.Count = 6
- Gridview1.Columns[iCol].Background = iBack[iCol]
- .Alignment = Align.Center
- ChangeColumnForeground(0, Color.White) ' (The Column number you want to change the colour, The colour you want to change it to)
- ChangeColumnForeground(1, Color.Yellow)
- ChangeColumnForeground(2, Color.Orange)
- ChangeColumnForeground(3, Color.Green)
- ChangeColumnForeground(4, Color.Blue)
- ChangeColumnForeground(5, Color.Black)
- Gridview1[iRow, iColumn].Foreground = iColor
Posted
Enthusiast

Dim iRow As Integer
For iRow = 0 To Gridview1.Rows.Max
Gridview1[iRow, iColumn].Foreground = iColor
Next
End
THANK you for that Cogier that worked perfectly that so I have add one option and now it works for all my griviews that I need to upate the font color
I added Gridview1 As GridView and when I call it now i use
ChangeColumnForeground(frmDashBoard.GridViewLast7Days, (i - 1), Color.Black)
SORRY I was not understanding but I did try everything everyone was showing me on the fourm but as normal Gambas was showing me errors on the thigs I tried.
I also could not understand how to do the change cell by cell and thanks to Cogier I understand how to to it now so I can update my other Form where needed
1 guest and 0 members have just viewed this.




