Alternative background colour in gridview component

Ask about the individual Gambas components here.
Post Reply
01McAc
Posts: 66
Joined: Sunday 24th January 2021 8:25pm

Alternative background colour in gridview component

Post by 01McAc » Sunday 07th February 2021 1:57pm

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.

User avatar
stevedee
Posts: 431
Joined: Monday 20th March 2017 6:06pm

Re: Alternative background colour in gridview component

Post by stevedee » Sunday 07th February 2021 3:03pm

01McAc wrote:
Sunday 07th 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

User avatar
cogier
Site Admin
Posts: 691
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Alternative background colour in gridview component

Post by cogier » Sunday 07th February 2021 3:59pm

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
Image

User avatar
stevedee
Posts: 431
Joined: Monday 20th March 2017 6:06pm

Re: Alternative background colour in gridview component

Post by stevedee » Sunday 07th February 2021 4:13pm

cogier wrote:
Sunday 07th February 2021 3:59pm
...Run this code in a Graphical Application...
Charlie, you forgot the Border variables!

User avatar
cogier
Site Admin
Posts: 691
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Alternative background colour in gridview component

Post by cogier » Sunday 07th February 2021 4:21pm

Charlie, you forgot the Border variables!
Sorry Steve. Now corrected, see my last post.

Image

01McAc
Posts: 66
Joined: Sunday 24th January 2021 8:25pm

Re: Alternative background colour in gridview component

Post by 01McAc » Sunday 07th 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!
Attachments
grid.jpg
grid.jpg (65.66 KiB) Viewed 871 times

User avatar
BruceSteers
Posts: 476
Joined: Thursday 23rd July 2020 5:20pm

Re: Alternative background colour in gridview component

Post by BruceSteers » Sunday 07th February 2021 9:07pm

01McAc wrote:
Sunday 07th 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.
Wishing well
Bruce

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

01McAc
Posts: 66
Joined: Sunday 24th January 2021 8:25pm

Re: Alternative background colour in gridview component

Post by 01McAc » Monday 08th February 2021 8:06am

BruceSteers wrote:
Sunday 07th 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.

User avatar
BruceSteers
Posts: 476
Joined: Thursday 23rd July 2020 5:20pm

Re: Alternative background colour in gridview component

Post by BruceSteers » Monday 08th February 2021 1:37pm

01McAc wrote:
Monday 08th February 2021 8:06am
BruceSteers wrote:
Sunday 07th 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 :)
Wishing well
Bruce

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

Post Reply