Gridview borders

Post

Posted
Rating:
#1 (In Topic #150)
Avatar
Guru
cogier is in the usergroup ‘Guru’
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: -

Code (gambas)

  1. GridViewCmdSearch.Row[0] = Border.Plain

Code (gambas)

  1. GridViewCmdSearch.Row[0].Border = Border.Plain

Code (gambas)

  1. GridViewCmdSearch[0,0].Border = Border.Plain

Code (gambas)

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

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’
Hi cogier, this is one of those cases where I find Gambas documentation pretty useless.

However, I discovered that this format seems to work;

Code (gambas)

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

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
Well done stevedee.  :D  Once you have done it and press[F2] you, belatedly, get: -

Image

(Click to enlarge)

___________________________________________

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

So my code is now: -

Code (gambas)

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

Post

Posted
Rating:
#4
Avatar
Regular
stevedee is in the usergroup ‘Regular’
Its certainly not a complete answer, and I've just looked at it again and found that using a Static Function:-

Code (gambas)

  1. GridView1[1, 1].Border = Border("style:double;color:Red")
…works just as well.

Also, if you type:-

Code (gambas)

  1. 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:-

Code (gambas)

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

Post

Posted
Rating:
#5
Avatar
Regular
stevedee is in the usergroup ‘Regular’
OK try this:-

Code (gambas)

  1. Public Sub Form_Open()
  2. Dim hBorder As Border
  3.  
  4. hBorder = New Border
  5. 'specify cell border
  6. With hBorder
  7.   .Width = 5
  8.   .Color = Color.Red
  9.   .BottomStyle = Border.Raised
  10.   .BottomColor = Color.DarkBlue
  11.   .TopColor = Color.Green
  12.  
  13. GridView1.Columns.Count = 3
  14. GridView1.Rows.Count = 4
  15. GridView1.Header = GridView1.Both
  16. GridView1.Columns.Width = 150
  17. GridView1.Rows[1].Height = 50
  18. GridView1[0, 1].Text = "jornmo"
  19. GridView1[1, 1].Text = "cogier"
  20. GridView1[2, 1].Text = "stevedee"
  21.  
  22. GridView1.Border = True   'enable control border
  23. GridView1[1, 1].Border = hBorder    'apply cell border
  24.  
Online now: No Back to the top

Post

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

Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Guru
cogier is in the usergroup ‘Guru’
I did a bit of digging into CSS syntax and came up with this modification to sevedee's code.

Code (gambas)

  1. hTimer As Timer
  2. siCount As Short
  3.  
  4. Public Sub Form_Open()
  5. Dim hBorder As Border
  6.  
  7. hTimer = New Timer As "Timer1"
  8. hTimer.start
  9.  
  10. hBorder = New Border
  11. 'specify cell border
  12. With hBorder
  13.   .Width = 5
  14.   .Color = Color.Red
  15.   .BottomStyle = Border.Raised
  16.   .BottomColor = Color.DarkBlue
  17.   .TopColor = Color.Green
  18.  
  19. GridView1.Columns.Count = 3
  20. GridView1.Rows.Count = 6
  21. GridView1.Header = GridView1.Both 'Interesting that "GridView1" works as well as "GridView"
  22. GridView1.Columns.Width = 150
  23. GridView1.Rows[1].Height = 50
  24. GridView1[0, 1].Text = "jornmo"
  25. GridView1[1, 1].Text = "cogier"
  26. GridView1[2, 1].Text = "stevedee"
  27. GridView1[5, 1].Text = "Hello world!"
  28. GridView1[5, 1].Alignment = Align.Center
  29. GridView1.Grid = False
  30. GridView1.Border = True   'enable control border
  31. GridView1[1, 1].Border = hBorder    'apply cell border
  32.  
  33.  
  34. Public Sub Timer1_Timer()
  35. Dim sBor As String[] = ["style:", "none ", "plain "]
  36. Dim sDer As String[] = ["02111", "01211", "01121", "01112", "021115", "02211", "02221", "02222"]
  37. Dim siCounter As Short
  38. Dim sTemp As String
  39.  
  40. For siCounter = 1 To 5
  41.   sTemp &= sBor[Mid(sDer[siCount], sicounter, 1)]
  42.  
  43. If siCount = sDer.Max Then GridView1[5, 1].Font.Bold = True Else GridView1[5, 1].Font.Bold = False
  44.  
  45. GridView1[5, 1].border = New Border(sTemp)
  46.  
  47. Inc siCount
  48. If siCount = sDer.Count Then siCount = 0
  49.  
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
Does this only work for gridview borders or can you change the colour and style on other controls?
Online now: No Back to the top

Post

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

Technopeasant said

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?

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
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.
Online now: No Back to the top

Post

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

Technopeasant said

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.

Yes I think that is the only option. My example just used a panel control slightly larger than the main control.

For anyone interested, here is my demo code using a TextArea and a Panel:-

Code (gambas)

  1. Public Sub SetBorder(iSize As Integer, iColour As Integer)
  2.  
  3.   TextArea1.Border = False
  4.   With Panel1
  5.     .NoTabFocus = True
  6.     .Left = TextArea1.Left - iSize
  7.     .Top = TextArea1.Top - iSize
  8.     .Width = TextArea1.Width + iSize * 2
  9.     .Height = TextArea1.Height + iSize * 2
  10.     .Background = iColour
  11.  

…and also a 1 second Timer to run it:-

Code (gambas)

  1. Public Sub Timer1_Timer()
  2. Dim iBorder As Integer
  3. Dim iColour As Integer
  4.  
  5.   iBorder = Rnd(0, 50)
  6.   iColour = Rnd(0, 16700000)
  7.   SetBorder(iBorder, iColour)
  8.   TextArea1.Text = " Border size: " & iBorder
  9.  
Online now: No Back to the top

Post

Posted
Rating:
#12
Avatar
Guru
cogier is in the usergroup ‘Guru’
I have had a look at this and I think the property to use is 'Padding'

Have a look at the attached (4 lines of code)

<IMG src="http://www.cogier.com/gambas/Borders.png"> </IMG>

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
 Might work for a panel, but does not seem to do what I want for picture boxes.

While it is disappointing that everything I read about how QT style sheets work suggests this should be possible, I have just implemented my own paint commands, which gave me the option of drawing ellipse borders as well.
Online now: No Back to the top

Post

Posted
Rating:
#14
Avatar
Guru
cogier is in the usergroup ‘Guru’
Might work for a panel, but does not seem to do what I want for picture boxes.

See attached, same as before but with a PictureBox. If this is not what you are looking for please elaborate.

<IMG src="http://www.cogier.com/gambas/Borders1.png"> </IMG>

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#15
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
Does the job for UI elements I guess, but my drawing commands are working out better for dynamic game elements. Thanks for the tips though.
Online now: No Back to the top
1 guest and 0 members have just viewed this.