Alternative background colour in gridview component

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

Alternative background colour in gridview component

Post 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.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Alternative background colour in gridview component

Post 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
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Alternative background colour in gridview component

Post 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
Image
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Alternative background colour in gridview component

Post by stevedee »

cogier wrote: Sunday 7th February 2021 3:59pm ...Run this code in a Graphical Application...
Charlie, you forgot the Border variables!
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Alternative background colour in gridview component

Post by cogier »

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

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

Re: Alternative background colour in gridview component

Post 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!
Attachments
grid.jpg
grid.jpg (65.66 KiB) Viewed 5986 times
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Alternative background colour in gridview component

Post 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.
If at first you don't succeed , try doing something differently.
BruceS
01McAc
Posts: 75
Joined: Sunday 24th January 2021 8:25pm

Re: Alternative background colour in gridview component

Post 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.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Alternative background colour in gridview component

Post 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 :)
If at first you don't succeed , try doing something differently.
BruceS
Post Reply