Alternative background colour in gridview component
Alternative background colour in gridview component
The Gridview component seems to have just one background colour for all rows in the grid. I'm wondering if it's possible to set a second alternative colour in the grid for a better overview and in order to keep track of the rows? E.g. first row: background white, second row: grey, third row: white, etc.
Re: Alternative background colour in gridview component
GridView formatting is quite flexible...
GridView1[1, 2].Background = Color.Pink GridView1[2, 2].Border = Border("margin:4;width:4;left-style:none;left-margin:0;left-width:0;top-right-radius:24;color:red") GridView1[3, 1].Font.Italic = True GridView1[3, 1].Foreground = Color.Blue
- cogier
- Site Admin
- Posts: 637
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Alternative background colour in gridview component
Hi 01McAc, Steve is correct. Run this code in a Graphical Application to see what can be done.

Gridview1 As GridView Public Sub Form_Open() Setupform DecorateGridview End Public Sub DecorateGridview() Dim iRow, iCol As Integer For iCol = 0 To Gridview1.Columns.Max For iRow = 0 To Gridview1.Rows.Max With Gridview1 .[iRow, iCol].Text = "Hello" .[iRow, iCol].Font.Bold = Rand(0, 1) .[iRow, iCol].Font.Italic = Rand(0, 1) .[iRow, iCol].Font.Size = Rand(8, 15) .[iRow, iCol].Alignment = Align.Center .[iRow, iCol].Background = Rand(0, 7000000) .[iRow, iCol].Foreground = Rand(9000000, 16000000) .[iRow, iCol].Border = Border("margin:1;width:1;left-style:none;left-margin:0;left-width:0;top-right-radius:5;color:red") End With Next Next Gridview1.Columns.Width = -1 End Public Sub Setupform() With Me .Height = 387 .Width = 500 .Arrangement = Arrange.Vertical .Padding = 5 End With With Gridview1 = New GridView(Me) .Expand = True .Columns.Count = 8 .Rows.Count = 17 End With End

- cogier
- Site Admin
- Posts: 637
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Alternative background colour in gridview component
Sorry Steve. Now corrected, see my last post.Charlie, you forgot the Border variables!

Re: Alternative background colour in gridview component
Thanks. The code works very well- but odd somehow as it doesn't work with any colour. I did try all the time with the wrong colours. Perhaps it is related with the dark mode settings on my desktop.
In any case it is not that colourful like your grid!
In any case it is not that colourful like your grid!
- Attachments
-
- grid.jpg (65.66 KiB) Viewed 228 times
- BruceSteers
- Posts: 362
- Joined: Thursday 23rd July 2020 5:20pm
Re: Alternative background colour in gridview component
If you.post your code we could see if it's your code or not.
Your theme should make no difference.
Other configs might.
Like if using gtk or qt or some less advanced desktops using an old gambas. Various things.
Post your failing code here.
Wishing well
Bruce
If at first you don't succeed , try it differently.
Bruce
If at first you don't succeed , try it differently.
Re: Alternative background colour in gridview component
Will do next time. I deleted already the failing code. I noticed btw that the gridview component is extremely fast when data are populated into the grid.
- BruceSteers
- Posts: 362
- Joined: Thursday 23rd July 2020 5:20pm
Re: Alternative background colour in gridview component
Well the code Cogier posted should work okay for you and show all you need to know about setting individual colours of your choice to each cell.
GridView is my favourite lister , If i need any sort of list in my apps i usually go for a GridView

Wishing well
Bruce
If at first you don't succeed , try it differently.
Bruce
If at first you don't succeed , try it differently.