Alternative background colour in gridview component

Post

Posted
Rating:
#1 (In Topic #576)
Regular
01McAc is in the usergroup ‘Regular’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

01McAc said

The Gridview component seems to have just one background colour for all rows in the grid….

GridView formatting is quite flexible…

Code (gambas)

  1.   GridView1[1, 2].Background = Color.Pink
  2.   GridView1[2, 2].Border = Border("margin:4;width:4;left-style:none;left-margin:0;left-width:0;top-right-radius:24;color:red")
  3.   GridView1[3, 1].Font.Italic = True
  4.   GridView1[3, 1].Foreground = Color.Blue
  5.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi 01McAc, Steve is correct. Run this code in a Graphical Application to see what can be done.

Code (gambas)

  1. Gridview1 As GridView
  2.  
  3. Public Sub Form_Open()
  4.  
  5.   Setupform
  6.   DecorateGridview
  7.  
  8.  
  9. Public Sub DecorateGridview()
  10.  
  11.   Dim iRow, iCol As Integer
  12.  
  13.   For iCol = 0 To Gridview1.Columns.Max
  14.     For iRow = 0 To Gridview1.Rows.Max
  15.       With Gridview1
  16.         .[iRow, iCol].Text = "Hello"
  17.         .[iRow, iCol].Font.Bold = Rand(0, 1)
  18.         .[iRow, iCol].Font.Italic = Rand(0, 1)
  19.         .[iRow, iCol].Font.Size = Rand(8, 15)
  20.         .[iRow, iCol].Alignment = Align.Center
  21.         .[iRow, iCol].Background = Rand(0, 7000000)
  22.         .[iRow, iCol].Foreground = Rand(9000000, 16000000)
  23.         .[iRow, iCol].Border = Border("margin:1;width:1;left-style:none;left-margin:0;left-width:0;top-right-radius:5;color:red")
  24.       End With
  25.     Next
  26.   Next
  27.  
  28.   Gridview1.Columns.Width = -1
  29.  
  30.  
  31. Public Sub Setupform()
  32.  
  33.   With Me
  34.     .Height = 387
  35.     .Width = 500
  36.     .Arrangement = Arrange.Vertical
  37.     .Padding = 5
  38.  
  39.   With Gridview1 = New GridView(Me)
  40.     .Expand = True
  41.     .Columns.Count = 8
  42.     .Rows.Count = 17
  43.  

<IMG src="https://www.cogier.com/gambas/GridColours.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
stevedee is in the usergroup ‘Regular’

cogier said

…Run this code in a Graphical Application…

Charlie, you forgot the Border variables!
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Guru
cogier is in the usergroup ‘Guru’
Charlie, you forgot the Border variables!

Sorry Steve. Now corrected, see my last post.

<IMG src="https://www.cogier.com/gambas/GridColours1.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
01McAc is in the usergroup ‘Regular’
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!

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

01McAc said

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

Post

Posted
Rating:
#8
Regular
01McAc is in the usergroup ‘Regular’

BruceSteers said

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

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’

01McAc said

BruceSteers said

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 :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.