Page 1 of 2

Gridview borders

Posted: Monday 8th January 2018 7:09pm
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?

Re: Gridview borders

Posted: Tuesday 9th January 2018 10:46am
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.

Re: Gridview borders

Posted: Tuesday 9th January 2018 11:55am
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 13826 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/

Re: Gridview borders

Posted: Tuesday 9th January 2018 2:24pm
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.

Re: Gridview borders

Posted: Tuesday 9th January 2018 3:12pm
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

Re: Gridview borders

Posted: Tuesday 9th January 2018 8:18pm
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!

Re: Gridview borders

Posted: Wednesday 10th January 2018 3:58pm
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

Re: Gridview borders

Posted: Sunday 8th December 2019 7:34pm
by Technopeasant
Does this only work for gridview borders or can you change the colour and style on other controls?

Re: Gridview borders

Posted: Monday 9th December 2019 4:36pm
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 10804 times

Re: Gridview borders

Posted: Wednesday 11th December 2019 2:12am
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.