Gridview borders

Post your Gambas programming questions here.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Gridview borders

Post by cogier »

Can anybody tell me how to get Gridview cell borders? The help says
This class defines constants used by the Border property of many controls. Moreover, since Gambas 3.7, this class is creatable, and allows to describe the border of a GridView cell or row.
I have tried: -
GridViewCmdSearch.Row[0] = Border.Plain
GridViewCmdSearch.Row[0].Border = Border.Plain
GridViewCmdSearch[0,0].Border = Border.Plain
GridViewCmdSearch[0, 0].Border("margin:4;width:4;left-style:none;left-margin:0;left-width:0;top-right-radius:24;right-color:green")
I've missed something, but what?
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Gridview borders

Post by stevedee »

Hi cogier, this is one of those cases where I find Gambas documentation pretty useless.

However, I discovered that this format seems to work;
GridView1[1, 1].Border = New Border("style:double;color:Red")
Unless something is obvious to beginners (& me), there needs to be a working example + a plain English {other languages are also available} description of how it works.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Gridview borders

Post by cogier »

Well done stevedee. :D Once you have done it and press[F2] you, belatedly, get: -
border.png
border.png (263.1 KiB) Viewed 13846 times
___________________________________________

Not that I know anything about 'CSS-like syntax'

So my code is now: -
GridViewCmdSearch[0, 0].Border = New Border("style:plain")
Joke
Son, pointing at the sky, asks father 'What are clouds made of Dad?". Father replies 'Mainly Linux servers son'. :lol:
I just heard that on MintCast https://mintcast.org/
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Gridview borders

Post by stevedee »

Its certainly not a complete answer, and I've just looked at it again and found that using a Static Function:-
GridView1[1, 1].Border = Border("style:double;color:Red")
...works just as well.

Also, if you type:-
GridView1[1, 1].Border. 
...you are offered a list of possible Properties. So it looks like it should be possible to do something like this:-
GridView1[1, 1].Border.BottomColor = Color.Red
...but this reports a 'Null Object' error, because in this context, Border is a Property, not a Class.

It really shouldn't be this difficult.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Gridview borders

Post by stevedee »

OK try this:-
Public Sub Form_Open()
Dim hBorder As Border

hBorder = New Border
'specify cell border
With hBorder
  .Width = 5
  .Color = Color.Red
  .BottomStyle = Border.Raised
  .BottomColor = Color.DarkBlue
  .TopColor = Color.Green
End With

GridView1.Columns.Count = 3
GridView1.Rows.Count = 4
GridView1.Header = GridView1.Both
GridView1.Columns.Width = 150
GridView1.Rows[1].Height = 50
GridView1[0, 1].Text = "jornmo"
GridView1[1, 1].Text = "cogier"
GridView1[2, 1].Text = "stevedee"

GridView1.Border = True   'enable control border
GridView1[1, 1].Border = hBorder    'apply cell border

End
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Gridview borders

Post by jornmo »

The object is useful if you want to use the border in several places.

That joke was exactly the way I like them - super dry!
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Gridview borders

Post by cogier »

I did a bit of digging into CSS syntax and came up with this modification to sevedee's code.
hTimer As Timer
siCount As Short

Public Sub Form_Open()
Dim hBorder As Border

hTimer = New Timer As "Timer1"
hTimer.start

hBorder = New Border
'specify cell border
With hBorder
  .Width = 5
  .Color = Color.Red
  .BottomStyle = Border.Raised
  .BottomColor = Color.DarkBlue
  .TopColor = Color.Green
End With

GridView1.Columns.Count = 3
GridView1.Rows.Count = 6
GridView1.Header = GridView1.Both 'Interesting that "GridView1" works as well as "GridView"
GridView1.Columns.Width = 150
GridView1.Rows[1].Height = 50
GridView1[0, 1].Text = "jornmo"
GridView1[1, 1].Text = "cogier"
GridView1[2, 1].Text = "stevedee"
GridView1[5, 1].Text = "Hello world!"
GridView1[5, 1].Alignment = Align.Center
GridView1.Grid = False
GridView1.Border = True   'enable control border
GridView1[1, 1].Border = hBorder    'apply cell border

End

Public Sub Timer1_Timer()
Dim sBor As String[] = ["style:", "none ", "plain "]
Dim sDer As String[] = ["02111", "01211", "01121", "01112", "021115", "02211", "02221", "02222"]
Dim siCounter As Short
Dim sTemp As String

For siCounter = 1 To 5
  sTemp &= sBor[Mid(sDer[siCount], sicounter, 1)]
Next

If siCount = sDer.Max Then GridView1[5, 1].Font.Bold = True Else GridView1[5, 1].Font.Bold = False

GridView1[5, 1].border = New Border(sTemp)

Inc siCount
If siCount = sDer.Count Then siCount = 0

End
User avatar
Technopeasant
Posts: 140
Joined: Saturday 13th July 2019 6:50pm
Location: Stony Plain, Alberta, Canada
Contact:

Re: Gridview borders

Post by Technopeasant »

Does this only work for gridview borders or can you change the colour and style on other controls?
Technical director,
Piga Software
http://icculus.org/piga/
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Gridview borders

Post by stevedee »

Technopeasant wrote: Sunday 8th December 2019 7:34pm Does this only work for gridview borders or can you change the colour and style on other controls?
It looks like it only works with GridView controls. The border property on most controls just turns it on/off, and it wont accept a bunch of style properties.

However, did you just want to create a simple border like this?
Border.png
Border.png (9.26 KiB) Viewed 10824 times
User avatar
Technopeasant
Posts: 140
Joined: Saturday 13th July 2019 6:50pm
Location: Stony Plain, Alberta, Canada
Contact:

Re: Gridview borders

Post by Technopeasant »

I wanted to be able to change the colour and size of the borders of my controls, but I might just have to add my own drawing code.
Technical director,
Piga Software
http://icculus.org/piga/
Post Reply