Change Font color in GridView

Post

Posted
Rating:
#1 (In Topic #2046)
Enthusiast
AndyGable is in the usergroup ‘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
But i can not work out how to set the font color (as For example on the red background black text is very hard to see my customers have said)

if someone would be as kind to show me how I can change the font color I would be most greatful.

Kind Regards
Andy

 
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Yogi)
#2
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Quincunxian is in the usergroup ‘Blogger’
Hi Andy.

Does the format
Gridview[RowNo , ColumnNo].Foreground = Color.Red
not work ?

Selection_001.png

This works for me with Gambas 3.21.3 on Linux Mint 22.3

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Yogi)
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’
I, like Quincunxian, also run Linux Mint 22.3 and Gambas 3.21.3. I have come up with the following code that I have tested using gb.gui and gb.gui.qt and here is the result and the code.



Run the code in a Graphical Application. I hope it helps.


Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Dim Gridview1 As Gridview
  4.   Dim iRow, iCol As Integer
  5.   Dim iBack As String[] = [Color.Black, Color.Blue, Color.Cyan, Color.DarkBlue, Color.DarkCyan, Color.Green]
  6.  
  7.   With Me
  8.     .Padding = 5
  9.     .Arrangement = Arrange.Vertical
  10.     .Height = 525
  11.     .Width = 375
  12.     .Center
  13.  
  14.   With GridView1 = New GridView(Me) As "Gridview1"
  15.     .Expand = True
  16.     .Rows.Count = 25
  17.     .Columns.Count = 6
  18.  
  19.   For iRow = 0 To Gridview1.Rows.Max
  20.     For iCol = 0 To Gridview1.Columns.Max
  21.         Gridview1.Columns[iCol].Background = iBack[iCol]
  22.       With GridView1[iRow, iCol]
  23.         .Text = Chr(Rand(65, 90))
  24.         .Alignment = Align.Center
  25.         .Font.Size = 16
  26.         .Font.Bold = True
  27.         .Foreground = Color(Rand(0, 255), Rand(0, 255), Rand(0, 255))
  28.       End With
  29.     Next
  30.   Next
  31.  
  32.  



Online now: No Back to the top

Post

Posted
Rating:
#4
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

Quincunxian said

Hi Andy.

Does the format
Gridview[RowNo , ColumnNo].Foreground = Color.Red
not work ?

Selection_001.png

This works for me with Gambas 3.21.3 on Linux Mint 22.3

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
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
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


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
Online now: No Back to the top

Post

Posted
Rating:
#6
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

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

That is really stange when I do use the .Foreground I get a error saying "Unkown Symbol 'Foreground' in class '_GridView_Column'


This is what I am using to create my gridview

Code (gambas)

  1. With frmDashBoard.GridViewSaleSummary
  2.     .Columns.Count = 4
  3.     .Columns[0].Width = 100 'Current Week
  4.     .Columns[1].Width = 100 'Last Week
  5.     .Columns[0].Alignment = Align.BottomLeft   'Current Day Figures
  6.     .Columns[1].Alignment = Align.BottomLeft   'Day 2
  7.     .Rows.Count = 4 .Rows.Resizable = False
  8.     .Columns.Resizable = False
  9.     .Rows[0].Text = "Customer Count"
  10.     .Rows[1].Text = " Sales Figures"
  11.     .Rows[2].Text = " Refund Figures"
  12.     .Rows[3].Text = " TOTAL(s)"
  13.     .Columns[0].Text = "Last Week"
  14.     .Columns[1].Text = "Current Week"
  15.     .Header = GridView.Both .ScrollBar = GridView.None
  16.     .SetFocus
  17.  


and then I call this code

Code (gambas)

  1. For i As Integer = 1 To 7
  2.     Dim TotalOfDay_Sales As Integer = GetSaleData(Format(DateAdd(StartDateLocal, gb.Day, -i), "yyyy/mm/dd"), "", "Sale", "No")
  3.     Dim TotalOfDay_Refunds As Integer = GetSaleData(Format(DateAdd(StartDateLocal, gb.Day, -i), "yyyy/mm/dd"), "", "Refund", "No")
  4.     Dim TotalOfDay As Integer = (TotalOfDay_Sales - TotalOfDay_Refunds)
  5.     Dim AllowedGapValue As Integer = (global.TotalDailyTarget - global.TotalAllowedGap)   'Show Customer Count
  6.     frmDashBoard.GridViewLast7Days[0, (i - 1)].Text = GetCustomerCount(Format(DateAdd(StartDateLocal, gb.Day, -i), "yyyy/mm/dd"), "")   frmDashBoard.GridViewLast7Days[0, (i - 1)].Alignment = Align.BottomRight   'show Sales
  7.     frmDashBoard.GridViewLast7Days[1, (i - 1)].Text = global.FormatCurrency(TotalOfDay_Sales, "Plus")
  8.     frmDashBoard.GridViewLast7Days[1, (i - 1)].Alignment = Align.BottomRight   'show Refund
  9.     frmDashBoard.GridViewLast7Days[2, (i - 1)].Text = global.FormatCurrency(TotalOfDay_Refunds, "Plus")
  10.     frmDashBoard.GridViewLast7Days[2, (i - 1)].Alignment = Align.BottomRight   'Total for the day
  11.     frmDashBoard.GridViewLast7Days[3, (i - 1)].Text = global.FormatCurrency(TotalOfDay, "Plus")
  12.     frmDashBoard.GridViewLast7Days[3, (i - 1)].Alignment = Align.BottomRight
  13.    
  14.     If TotalOfDay > 0 Then
  15.        If TotalOfDay > global.TotalDailyTarget Then frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.green frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.Black
  16.       Else If TotalOfDay = global.TotalDailyTarget Then
  17.           frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.Orange
  18.           frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.Black
  19.       Else If TotalOfDay >= AllowedGapValue And TotalOfDay <= global.TotalDailyTarget Then
  20.           frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.Yellow
  21.           frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.Black
  22.       Else frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.red
  23.              frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.white
  24.     End If
  25.     Else frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Background = Color.white
  26.              frmDashBoard.GridViewLast7Days.Columns[(i - 1)].Foreground = Color.Black
  27.     End If
  28.  

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

Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly is in the usergroup ‘Blogger’
gbWilly is in the usergroup ‘GambOS Developer’
Since Gambas 3.1

post.png


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 :thumbs:


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.

post1.png

post.png

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!
Online now: No Back to the top

Post

Posted
Rating:
#8
Enthusiast
AndyGable is in the usergroup ‘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.





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
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Yogi)
#9
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly is in the usergroup ‘Blogger’
gbWilly is in the usergroup ‘GambOS Developer’

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?

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 O_o


Enjoy…:thumbs:


 

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!
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
This is the code for the config panel. It gives a "live" preview for setting the GV colors for the backgroun and, current day border.

Code (gambas)

  1. Public Sub gvPreview()
  2.  
  3.     Dim hCurrentDayColor As Border
  4.  
  5.     hCurrentDayColor = New Border
  6.     With hCurrentDayColor        'specify cell border
  7.       .Width = SpinBox3.Value
  8.       .Color = ColorButton5.Value
  9.     End With
  10.  
  11.     gridviewPreview.Columns.Count = 1
  12.     gridviewPreview.Rows.Count = 1
  13.     gridviewPreview.Columns.Width = 65
  14.     gridviewPreview.Rows.Height = 86
  15.     gridviewPreview[0, 0].Border = hCurrentDayColor
  16.     gridviewPreview[0, 0].Background = ColorButton6.Value
  17.  
  18.  

Image

calendar_config.png

calendar_config.png

(Click to enlarge)

   
Image

calendar_config_live.png

calendar_config_live.png

(Click to enlarge)


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)

  1. Public Sub BuildCal()
  2.  
  3.     Dim iH As Byte              ' day of week
  4.     Dim iQ As Byte              ' day of month
  5.     Dim iMm As Short            ' month
  6.     Dim iM As Short             ' month
  7.     Dim iYy As Short            ' year
  8.     Dim iY As Short             ' year
  9.     Dim iRow As Byte            ' grid row
  10.     Dim iCol As Byte            ' grid column
  11.     Dim i As Byte               ' days counter for grid
  12.     Dim iJ As Byte              ' century
  13.     Dim iK As Byte              ' year in century
  14.     Dim iStart As Integer
  15.     Dim iEnd As Integer
  16.     Dim iCount As Byte
  17.  
  18.     Dim hCurrentDayBorder As Border
  19.  
  20.     hCurrentDayBorder = New Border
  21.     With hCurrentDayBorder        'specify cell border
  22.       .Width = MGlobal.hSetting["System/Calendar/CurrentDay/Border", 5]
  23.       .Color = MGlobal.hSetting["System/Calendar/CurrentDay/Color", &HFFFFBF&]
  24.     End With
  25.  
  26.     gvCalendar.Clear
  27.  
  28.     iY = sbYear.Value
  29.     iM = cmbMonth.Index
  30.  
  31.     If iM > 0 Then      ' on start up, iM is a negative number. this could possibly cause an error. this if...then blocks any negative iM value
  32.         MGlobal.hResData = MGlobal.hDB.Exec("SELECT COUNT(date) As Number From schedule")
  33.         iCount = MGlobal.hResData!Number
  34.  
  35.         ' the next 2 lines preserve our original year and month values from the combo
  36.         ' and spin boxes for use in our "days to month" map below
  37.         iMm = iM
  38.         iYy = iY
  39.  
  40.         ' map combo and spinbox values to Zeller's Rule formula.
  41.         ' March becomes 1 st month, and Jan/Feb become 11/12 respectively.
  42.         iMm -= 2                    ' subtract 2 from the combobox value. this aligns months 1 - 10 with the rule.
  43.         If iMm < 1 Then          '   this makes Jan/Feb months 11/12 respectively
  44.             iMm += 12
  45.             iYy -= 1                   ' Jan/Feb months need 1 subtracted from the year for the rule to work.
  46.         Endif
  47.  
  48.         Select Case iM          ' map number of days to given month
  49.           Case 1, 3, 5, 7, 8, 10, 12
  50.             iDays = 31
  51.           Case 4, 6, 9, 11
  52.             iDays = 30
  53.           Case 2
  54.             If Frac(iY / 4) > 0 Then iDays = 28     'is leap year = False
  55.             If Frac(iY / 4) = 0 Then iDays = 29     'is leap year = True
  56.             If Frac(iY / 100) = 0 Then iDays = 28   'is leap year = False
  57.             If Frac(iY / 400) = 0 Then iDays = 29   'is leap year = True
  58.         End Select
  59.  
  60.         iQ = 1                          ' sets which day of month we want to find the day of week for.
  61.         iK = iYy Mod 100                ' extract century
  62.         iJ = Floor(iYy / 100)           ' extract 2 digit year
  63.         iH = (iQ + (Floor((13 * iMm - 1) / 5)) + iK + (Floor(iK / 4)) + Floor(iJ / 4) + (5 * iJ))   ' Zeller's Rule
  64.         iH = iH Mod 7
  65.  
  66.         ' create the calendar
  67.         iRow = 0
  68.         iCol = iH
  69.  
  70.         ' this sets the number of rows needed for the number of days in the month.
  71.         ' a few months require an extra row when the month starts on a thursday, friday, or saturday and has > 29 days.
  72.         If Frac((iDays - (7 - iCol)) / 7) > 0 Then
  73.             gvCalendar.Rows.Count = Int((iDays - (7 - iCol)) / 7) + 2
  74.         Else
  75.             gvCalendar.Rows.Count = Int((iDays - (7 - iCol)) / 7) + 1
  76.         Endif
  77. ' db.Debug = True
  78.         For i = 1 To iDays
  79.             gvCalendar[iRow, iCol].Text = i
  80.             gvCalendar[iRow, iCol].Alignment = Align.TopLeft
  81.             gvCalendar[iRow, iCol].Background = &HFFFFFF&       ' clear all cells of color
  82.             ' If i = Day(Now) Then gvCalendar[iRow, iCol].Background = MGlobal.hSetting["System/Calendar/CurrentDay/Color", &HFFFFBF&]    ' add color to today's date
  83.             If i = Day(Now) Then gvCalendar[iRow, iCol].Border = hCurrentDayBorder    ' add color to today's date
  84.             iStart = DateDiff(CDate("1/1/1970"), (iM & "/" & i & "/" & iY), gb.Second) + MGlobal.iDST
  85.             iEnd = iStart + 86400
  86.             If iCount > 0 Then
  87.                 MGlobal.hResData = MGlobal.hDB.Exec("SELECT * FROM schedule WHERE date > &1 AND date < &2", iStart, iEnd)
  88.                 If MGlobal.hResData.Available Then
  89.                     gvCalendar[iRow, iCol].Background = MGlobal.hSetting["System/Calendar/Reminder", &H00FFFF&]    ' add color to reminder days
  90.                 Endif
  91.             Endif
  92.             Inc iCol
  93.             If iCol = 7 And i < iDays Then          ' when we've populated saturday's cell...
  94.                 iCol = 0            ' reset the column count to 0, and...
  95.                 iRow += 1           ' increment the row count.
  96.             Endif
  97.         Next
  98.     Endif
  99. ' db.Debug = False
  100.  

Image

calendar.png

calendar.png

(Click to enlarge)





(If I remember correctly gbWilly helped with figuring out a few things with the functionality of the calendar.  :thumbs: )









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
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by gbWilly)
#11
Avatar
Administrator
sholzy is in the usergroup ‘unknown’

AndyGable said

Also sorry about the code thing I am still getting use to the new website

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
Online now: No Back to the top

Post

Posted
Rating:
#12
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly is in the usergroup ‘Blogger’
gbWilly is in the usergroup ‘GambOS Developer’

sholzy said

(If I remember correctly gbWilly helped with figuring out a few things with the functionality of the calendar.  :thumbs: )
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 time

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!
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
 :offtopic:    :sinner:     :)

gbWilly said

sholzy said

(If I remember correctly gbWilly helped with figuring out a few things with the functionality of the calendar.  :thumbs: )
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 time


Looking at the build logs… the first build was May 4, 2016. 10 year anniversary coming up!   :thumbs:

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
Online now: No Back to the top

Post

Posted
Rating:
#14
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’

AndyGable said

so would frmDashBoard.GridViewLast7Days.Row[(i - 1)].Foreground = Color.Black work or am i on a copmpletely wrong trail of thought?
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.

Have a look at my revised code that changes the Column Foreground using the Sub Routine ChangeColumnForeground.


Code (gambas)

  1. ' Gambas class file
  2.  
  3. Gridview1 As Gridview
  4.  
  5. Public Sub Form_Open()
  6.  
  7.   Dim iRow, iCol As Integer
  8.   Dim iBack As String[] = [Color.Black, Color.Blue, Color.Cyan, Color.DarkBlue, Color.DarkCyan, Color.Green]
  9.  
  10.   With Me
  11.     .Padding = 5
  12.     .Arrangement = Arrange.Vertical
  13.     .Height = 525
  14.     .Width = 375
  15.     .Center
  16.  
  17.   With GridView1 = New GridView(Me) As "Gridview1"
  18.     .Expand = True
  19.     .Rows.Count = 25
  20.     .Columns.Count = 6
  21.  
  22.   For iRow = 0 To Gridview1.Rows.Max
  23.     For iCol = 0 To Gridview1.Columns.Max
  24.       Gridview1.Columns[iCol].Background = iBack[iCol]
  25.       With GridView1[iRow, iCol]
  26.         .Text = Chr(Rand(65, 90))
  27.         .Alignment = Align.Center
  28.         .Font.Size = 16
  29.         .Font.Bold = True
  30.       End With
  31.     Next
  32.   Next
  33.  
  34.   ChangeColumnForeground(0, Color.White) ' (The Column number you want to change the colour, The colour you want to change it to)
  35.   ChangeColumnForeground(1, Color.Yellow)
  36.   ChangeColumnForeground(2, Color.Orange)
  37.   ChangeColumnForeground(3, Color.Green)
  38.   ChangeColumnForeground(4, Color.Blue)
  39.   ChangeColumnForeground(5, Color.Black)
  40.  
  41.  
  42. Public Sub ChangeColumnForeground(iColumn As Integer, iColor As Integer)
  43.  
  44.   Dim iRow As Integer
  45.  
  46.   For iRow = 0 To Gridview1.Rows.Max
  47.     Gridview1[iRow, iColumn].Foreground = iColor
  48.   Next
  49.  
  50.  
  51.  


Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by sholzy)
#15
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Public Sub ChangeColumnForeground(iColumn As Integer, iColor As Integer)
  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

 
Online now: No Back to the top
1 guest and 0 members have just viewed this.