Page 1 of 1
Alternative background colour in gridview component
Posted: Sunday 7th February 2021 1:57pm
by 01McAc
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
Posted: Sunday 7th February 2021 3:03pm
by stevedee
01McAc wrote: ↑Sunday 7th February 2021 1:57pm
The Gridview component seems to have just one background colour for all rows in the grid....
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
Re: Alternative background colour in gridview component
Posted: Sunday 7th February 2021 3:59pm
by cogier
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
Re: Alternative background colour in gridview component
Posted: Sunday 7th February 2021 4:13pm
by stevedee
cogier wrote: ↑Sunday 7th February 2021 3:59pm
...Run this code in a Graphical Application...
Charlie, you forgot the Border variables!
Re: Alternative background colour in gridview component
Posted: Sunday 7th February 2021 4:21pm
by cogier
Charlie, you forgot the Border variables!
Sorry Steve. Now corrected, see my last post.
Re: Alternative background colour in gridview component
Posted: Sunday 7th February 2021 7:00pm
by 01McAc
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!
Re: Alternative background colour in gridview component
Posted: Sunday 7th February 2021 9:07pm
by BruceSteers
01McAc wrote: ↑Sunday 7th February 2021 7:00pm
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!
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.
Re: Alternative background colour in gridview component
Posted: Monday 8th February 2021 8:06am
by 01McAc
BruceSteers wrote: ↑Sunday 7th February 2021 9:07pm
Post your failing code here.
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.
Re: Alternative background colour in gridview component
Posted: Monday 8th February 2021 1:37pm
by BruceSteers
01McAc wrote: ↑Monday 8th February 2021 8:06am
BruceSteers wrote: ↑Sunday 7th February 2021 9:07pm
Post your failing code here.
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.
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